Thursday, June 13, 2013

Switching from one frame to Another

One of the Classic Scenario that is faced by newbies in Selenium ( yes, i am a newbie too.. ) is that IDE locates the element when clicked and Highlighted but when Code in Java ( i love java ..u can choose any language you are good into) is ran it shows error element not found ...blah blah.


This is because there is an iframe in which your element is located and you are trying to locate that without switching the frame.

Simple Step to do this is as follow :-

WebElement i_frame = driver.findElement(By.xpath("/html/body/div/div[2]/div/div/iframe"));
// you can find the element iFrame by any other suitable method like id , css  locator etc .
driver.switchTo().frame(i_frame);  // switching is done ..now happy execution....

See below pic whichh shows presence of Iframe in HTML source code.

No comments:

Post a Comment