1
我們正在嘗試使用Powershell在我們的網站上自動執行一些測試。 當我們在打開新選項卡的定位點上發出點擊事件時,我們遇到了問題。 我們需要在新選項卡上獲得句柄,然後通過單擊新選項卡上的打印按鈕繼續處理。 這怎麼可以使用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的新手,所以任何幫助,將不勝感激。
感謝 理查德
你能分享你的代碼嗎? – David
不容易在沒有看到您的代碼的情況下回答您的問題。不過,您可以在這裏找到一些曲目:http://msdn.microsoft.com/en-us/magazine/cc163301.aspx –