我们正在尝试使用 Powershell 来自动化我们网站上的一些测试。当我们在打开一个新标签的锚点上发出点击事件时,我们遇到了一个问题。我们需要处理新选项卡,然后通过单击新选项卡上的打印按钮继续处理。使用 Powershell 怎么能做到这一点?
set-executionpolicy remotesigned
$ie = new-object -com "InternetExplorer.Application"
$ie.navigate("xxxxx.com")
$ie.visible = $true
$doc = $ie.document
While ($ie.Busy) {Sleep 10}
$doc -eq $null
$tb1 = $doc.getElementByID("username")
$tb2 = $doc.getElementByID("password")
$tb1.value = "xxxxxxxxxxx"
$tb2.value = "xxxxxxxxxxx"
$btn = $ie.document.getelementsbytagname("input")|where{$_.name -eq "Submit"}
$btn.click()
$ie.navigate("xxxxx.com/admin/reports.html#")
$link = $ie.Document.getElementsByTagName('A') | where-object {$_.innerText -eq 'All Photos'}
$link.click()
<<<<<<<<<<< it's here where a new tab is open and we need to get a handle on the new page to be able to click the print button >>>>>>>>>>>
$popupHandle = $ie.openwindow.winrefs[$targetName]
$btn = $popupHandle.document.getelementsbytagname("input")|where{$_.name -eq "print"}
$btn.click()
我们是 Powershell 的新手,因此我们将不胜感激。
谢谢理查德