Quality Testing

Quality is delighting customers

Can any one explain how we can switch to frames, ?

Can any one explain how we can switch to frames, if possible provide a sample code.

Views: 323

Reply to This

Replies to This Discussion

driver.switchTo().frame("cq-cf-frame");        // cq-cf-frame is frame name

driver.switchTo().defaultContent(); // you are now outside both frames

You can use following code, if you don't know frame id:

{

driver.get("URL");

driver.findElement(By.xpath("Xpath-expression"));

List<WebElement> frames = driver.findElements(By.tagname("iframe"));

system.out.println("Total Frames" + frames.size());

for(i=0; i<=frames.size; i++){

int frameID=frames.get(i).get("id");

driver.switchTo().frame(frameID);

}

}

If you know frame id you can simply use following code:

driver.switchTo().frame(id);

Hope this will help you.

Hi All,

Below website automated testing code help in managing the frames:

 public void switchToFrame(int frame) {
try { driver.switchTo().frame(frame);
System.out.println("Navigated to frame with id " + frame); }
catch (NoSuchFrameException e) {
System.out.println("Unable to locate frame with id " + frame + e.getStackTrace());
}


catch (Exception e) {
System.out.println("Unable to navigate to frame with id " + frame + e.getStackTrace());
}

}
Hope this will help you.

RSS

TTWT Magazine


Advertisement

Advertisement

Advertisement

Advertisement

© 2019   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service