Shailesh Dubey
Shailesh Dubey

Reputation: 1

Unable to click on this button using webdriver

http://www.w3schools.com/js/tryit.asp?filename=tryjs_alert

Above is the website, cant click on that "try it", no locator techniques working ?

Below is the code used

driver.get("http://www.w3schools.com/js/tryit.asp?filename=tryjs_alert");
driver.findElement(By.xpath(".//button[@onclick='myFunction()']")).click();

Upvotes: 0

Views: 59

Answers (1)

NarendraR
NarendraR

Reputation: 7708

Your element is iniFrame so first you need to switch into frame and then have to perform your actions.

Use this :

driver.switchTo().frame(driver.findElement(By.id("iframeResult")));

driver.findElement(By.xpath(".//button[@onclick='myFunction()']")).click();

Use following code to switchback from the iframe and do your actions other then this frame's element:

driver.switchTo().defaultContent();

Upvotes: 1

Related Questions