Selenium Webdriver无法找到第三个浏览器弹出窗口

时间:2015-12-17 05:50:23

标签: selenium selenium-webdriver

我试图点击弹出窗口中的链接。这是点击链接时打开的第三个窗口。我尝试使用getWindowHandles函数但是webdriver无法获得第三个窗口。

它打印两个窗口的id,但是当第三个窗口打开时,它无法找到它。请参阅下面的屏幕截图:

enter image description here



<body onunload="MyAction('Details')">
<div class="whiteDiv">
<form name="ModalForm">
<div class="title" width="98%">What would you like to do next?</div>
<div style="padding:0 20px 20px 20px;line-height:1.5em">
<img width="16" height="16" align="absmiddle" alt="View Details " src="/common/v1/images/icons/folder.png">
<a class="linkAction" onclick="MyAction('Details'); return false;" href="#">View Details</a>
<br>
<img width="16" height="16" align="absmiddle" alt="Schedule Next Action" src="/common/v1/images/icons/action_new.png">
<a class="linkAction" onclick="MyAction('NextAction'); return false;" href="#">Schedule Next Action</a>
<br>
<img width="17" height="16" align="absmiddle" alt="Send an email" src="/common/v1/images/icons/email_send.png">
<a class="linkAction" onclick="MyAction('Email'); return false;" href="#">Send an email</a>
<br>
<img width="16" height="16" align="absmiddle" alt="Write A letter" src="/common/v1/images/icons/letter_send.png">
<a class="linkAction" onclick="MyAction('Letter'); return false;" href="#">Write a letter</a>
<br>
<img width="16" height="16" align="absmiddle" alt="Make a phone call" src="/common/v1/images/icons/phone_out.png">
<a class="linkAction" onclick="MyAction('Phone'); return false;" href="#">Make a phone call</a>
<br>
<img width="16" height="16" align="absmiddle" alt="Add a meeting note" src="/common/v1/images/icons/note_new.png">
<a class="linkAction" onclick="MyAction('Note'); return false;" href="#">Add a meeting note</a>
<br>
<img width="16" height="16" align="absmiddle" alt="Schedule Next Action" src="/common/v1/images/icons/action_new.png">
<a class="linkAction" onclick="MyAction('Close'); return false;" href="#">Close details window</a>
</div>
</form>
<script language="javascript">
</div>
</body>
&#13;
&#13;
&#13;

driver.switchTo().window(window2);        
driver.findElement(By.linkText("Call")).click();    
System.out.println("\nClicked on Call link");    
Thread.sleep(3000);     
driver.findElement(By.id("saveRecord")).click(); // It stucks on this line although it clicked on the link

System.out.println("\nClicking on Save Record link");    
driver.switchTo().activeElement();    
Assert.assertTrue(driver.findElement(By.linkText("View Details")).isDisplayed());    
driver.findElement(By.linkText("View Details")).click();

2 个答案:

答案 0 :(得分:1)

尝试使用Actions并查看是否能够成功点击:

Actions actionbuilder = new Actions(driver);
actionbuilder .moveToElement(webelement).click().build().perform();

答案 1 :(得分:0)

您可以尝试使用driver.switchTo().activeElement();并检查是否有帮助。
如果这有助于你,请告诉我们。