Varesh Tuli
Varesh Tuli

Reputation: 45

Selenium Webdriver is not able to locate the third browser popup window

I am trying to click on a link in a popup window. This the third window which is opened on clicking on a link. I tried with getWindowHandles function but webdriver is not able to get the third window.

It prints the id of two windows but when the third window gets open it is not able to locate it. Please see the screenshot below:

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>

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();

Upvotes: 1

Views: 209

Answers (2)

Abhinav
Abhinav

Reputation: 1027

Try using Actions and see if it able to click successfully:

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

Upvotes: 1

Abhinav
Abhinav

Reputation: 1027

Can you please try using driver.switchTo().activeElement(); and check if that helps.
Do let us know if that helps you out.

Upvotes: 0

Related Questions