2013-01-23 3 views
1

Powershell을 사용하여 사이트에서 일부 테스트를 자동화하려고합니다. 새 탭을 여는 앵커에서 click 이벤트를 발행 할 때 문제가 발생했습니다. 새 탭에서 핸들을 가져온 다음 새 탭에서 인쇄 버튼을 클릭하여 처리를 계속해야합니다. 어떻게 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을 (를) 처음 사용했습니다.

감사 리처드

+0

코드를 공유 할 수 있습니까? – David

+0

코드를 보지 않고도 쉽게 대답 할 수 있습니다. 그러나 다음 트랙을 찾을 수 있습니다. http://msdn.microsoft.com/en-us/magazine/cc163301.aspx –

답변

1

보십시오 새 전경 탭에 넣어 $ ie.navigate2 및 0x0800를 사용하여 새 탭을 열고. 그러면 자동으로 새 탭으로 이동하여 인쇄 버튼을 잡을 수 있습니다.

# Setting page to new foreground tab here 
$newTabPage = $ie.navigate2("www.xxxx.com",0x0800) 

마찬가지로, 당신은 새 탭을 열 수 있지만 자동으로 초점을 가져올 새로운 배경 탭에서 페이지를 열 수 가 0x1000를 사용할 수 있습니다.

# Setting page to new background tab here 
$newTabPage = $ie.navigate2("www.xxxx.com",0x1000)