RE: Clicking a LinkValue in a Child Window and Passing Value to parent window.

I have a web application where i have a image, when i click on that image a new pop up window opens, which shows list of values. There is a Javascript executed when i click on any value.When i click on any value that value is passed to the parent window in a text field.
How can i achieve this through Selenium. Your help will be appreciated. Below the HTML of the link .

<a href=”javascript:passBack(v[1], v2[1]);>583 – WALNUT DISTRIBUTION CENTER</a>

rehanshahid Train Asked on November 3, 2015 in Selenium WebDriver.
Add Comment
4 Answers

You need to capture the window handles using the below syntax –

String parentWindow = driver.getWindowHandle();
Set<String> handles = driver.getWindowHandles();
System.out.println(handles);
for(String windowHandle : handles)
{
if(!windowHandle.equals(parentWindow))
{
driver.switchTo().window(windowHandle);
// Perform the click operation in child window

// …

// Close the child window in case if you are done with the operation or you can just leave it in case if there  are any other operations pending so that you can switch to child window

driver.close();

//Switch to parent window

driver.switchTo().window(parentWindow);

//verify the text here..

}

}

 

Train Answered on November 4, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.