我想点击一个链接,我已经使用PowerShell过滤了
以下是代码:
$ie.Document.getElementByTagName("a")| foreach {
if ($_.href -eq "name.pdf"){
$_.click()
}
}
当我运行脚本时,我收到如下错误:
FullyQualifiedErrorId:InvokeMethodOnNull
但我不知道什么是错的,这是HTML代码:
<td><a href="javascript:NewWindow('name.pdf')">Name of the link</a>
我会感激任何帮助。
提前致谢
以下是整个PowerShell代码:
$ie = new-object -com internetexplorer.application
$ie.visible=$true
$ie.navigate('url')
while($ie.busy) {
sleep 5
}
$ie.Document.getElementByTagName("a")| foreach {
if ($_.href -eq "name.pdf"){ # or eq Name of the link
$_.click()
}
}
答案 0 :(得分:0)
你做错了两件事。
eq不能像
一样使用$ url =“https://stackoverflow.com/”
$ ie = new-object -com internetexplorer.application
$ ie.visible = $真
$ ie.navigate($ URL)
while($ie.busy) {
sleep 5
}
$links = $ie.Document.GetElementsByTagName("a")
foreach ($a in $links){
$href = $a.href
if ($href -like '*questions*' )
{
print "Found Link : $href Clicking"
$a.click()
break
}
}