我试图让powershell脚本打开互联网浏览器,这样做,并去一个网站,并点击一个单选按钮。我收到的错误告诉我,与getElementsByTagName的行。它还说,我不能对下面所有行的空值表达式调用一个方法,并包括getElementsByTagName。
$ie = New-Object -com "InternetExplorer.Application"
$ie.Navigate("hidden")
$ie.visible = $true
$doc = $ie.documentElement
$myradio = $doc.getElementsByTagName('radio')|?{$_.type -eq 'radio' -and $_.name -eq 'export'}
$x = 2 #specific radio button
$myradio.setActive()
$myradio.click()发布于 2016-01-06 20:50:56
我想明白了,所以对于我来说,我必须首先启动$ie部分,然后用我的方式完成它。如果IE不打开,Powershell将不会选择COM对象。一旦那部分被弄明白了,一切都像魅力一样运作。
#gathers COm Objects for IE
$ie = New-Object -ComObject internetexplorer.application;
#Opens IE and navigates to the site
$ie.visible = $true;
foreach($s in $site){
$sName = $s.ServerName
$sLink = $s.Link
"`n"
$url = $site+$results
$ie.navigate($s.Link);
#sleeps for a second
while ($ie.Busy -eq $true)
{
Start-Sleep -Milliseconds 1000;
}
#gets export button radio and clicks it
$ie.document.getElementById('exp').click();
#sleeps for another second for page to load
while ($ie.Busy -eq $true)
{
Start-Sleep -Milliseconds 1000;
}
#Clicks search button for results page
$button = $ie.Document.getElementsByName('search') | Where-Object {$_.type -eq "button"}
$button.click();https://stackoverflow.com/questions/32379589
复制相似问题