Need to Locate JavaScript Link

a Javascript link appear in a child pop up window when i Click on an image in Parent Window.

I need to locate this webElement. Here is my code.

driver.findElement(By.xpath(“html/body/form/div[2]/a”)).click();
JavascriptExecutor executor = (JavascriptExecutor)driver
executor.executeScript(passBack(v[1], v2[1]).click()”;

The link in a new popup window which i am not able to locate.

rehanshahid Train Asked on November 2, 2015 in Selenium WebDriver.
Add Comment
3 Answer(s)

It will be better if you can share corresponding HTML? a link to the site where we can see the issue?

Virender

Virender Singh Professor Answered on November 2, 2015.
Add Comment

below is the HTML of the link.

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

I am trying to click on this link with linkText name =583 – WALNUT DISTRIBUTION CENTER. but does not work

rehanshahid Train Answered on November 3, 2015.
Add Comment

executor.executeScript(passBack(v[1], v2[1]).click()”);

this is a wrong statement. The reason is that javascript:passBack(v[1], v2[1] is a function call where v[1], v2[1] will have runtime values.

I would suggest you can find the element using findElementByLinkText method. You also mentioned its a link in a new window. I am wondering if the new window is an alert. If its an alert you will have to switch to alert before trying to access the element.

http://www.toolsqa.com/selenium-webdriver/handling-of-alerts-javascript-alerts-and-popup-boxes/

Virender

Virender Singh Professor Answered on November 4, 2015.
Add Comment

Your Answer

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