单击JavaScript按钮的PowerShell脚本
我目前正在使用PowerShell脚本启动页面并单击按钮。该按钮是一个JavaScript按钮,没有>标记。这两个变量都返回您不能对空值表达式调用方法。我肯定我在绕着答案转,但我仍然在等待。提前谢谢单击JavaScript按钮的PowerShell脚本,javascript,powershell,Javascript,Powershell,我目前正在使用PowerShell脚本启动页面并单击按钮。该按钮是一个JavaScript按钮,没有>标记。这两个变量都返回您不能对空值表达式调用方法。我肯定我在绕着答案转,但我仍然在等待。提前谢谢 $ie = new-object -com internetexplorer.application $ie.visible=$true $ie.navigate('http://192.168.63.10/counters/usage.php') while($ie
$ie = new-object -com internetexplorer.application
$ie.visible=$true
$ie.navigate('http://192.168.63.10/counters/usage.php')
while($ie.busy) {sleep 1}
$link = @($ie.Document.getElementsByTagName('button')) | Where-Object {$_.innerText -eq 'Download File to Your Computer'}
$link.click()
我也试过:
$link2 = $ie.Document.documentElement.getElementsByClassName('horizButtonBarAboveTableLeft')| Where-Object {$_.innerText -eq 'Download File to Your Computer'}
$link2.click()
这是HTML(希望使用GenerateCsvFile()单击按钮:)
刷新
将文件下载到您的计算机
您的Where Object子句失败,因为innerText中有额外的空格,导致相等条件失败。因此,
$link
变量为空。这会导致无法对空值表达式调用方法的错误。试着删减空白
Where-Object { $_.innerText.Trim() -eq 'Download File to Your Computer' }
谢谢你的回复。不幸的是,即使使用Trim函数,它仍然返回null。我想知道$ie.Document.getElementsByTagName('button')是否是问题的原因。看起来问题与Windows 10和PS 5有关。我发现了几个有类似问题的线程。我从来没有考虑过,因为错误并没有真正指向那个方向。喝倒采我假设问题出在InternetExplorer com对象上。是的,这就是问题所在。此后,我使用invokewebrequest以另一种方式处理了该任务,该方法运行良好。
Where-Object { $_.innerText.Trim() -eq 'Download File to Your Computer' }