0
我目前正在使用PowerShell脚本启动页面并单击按钮。该按钮是一个JavaScript按钮,没有< < a >>标签。两种变体均返回您无法在空值表达式上调用方法。我确信我正在盘旋答案,但我仍然处于持有模式。提前致谢!单击JavaScript按钮的PowerShell脚本
$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():)按钮
<div class="horizButtonBarAboveTableLeft">
<button onclick="document.location=document.URL">
<img src="/images/counters/refresh_renew_32.png" alt="" width="32" height="32">
Refresh </button>
<img src="/images/ClearGIF.gif" width="19" height="20" alt="">
<button onclick="GenerateCsvFile();">
<img src="/images/counters/download_import_32.png" alt="" width="32" height="32">
Download File to Your Computer </button>
感谢您的回复。不幸的是即使使用修剪功能它仍然返回一个空值。我想知道如果$ ie.Document.getElementsByTagName('按钮')是造成这个问题。 –
奇怪的是,我有你的代码在本地工作。 – Cobster
看起来问题与Windows 10和PS 5有关。我发现有几个线程有类似的问题。我从来没有考虑过它,因为错误并没有真正指向那个方向。嘘! –