Pages

Showing posts with label Frame. Show all posts
Showing posts with label Frame. Show all posts

Sunday, 26 February 2012

I would like to know all the frames available on the page, how can I get that?

We can get a list of frame names available on a page as below:


	//Make sure you are in default frame
driver.switchTo().defaultContent();
List framesetList=driver.findElements(By.tagName("frame"));
if(framesetList.size()>0){
for(WebElement framename :framesetList){
System.out.println("Frame with name:" + framename.getAttribute("name")+" found.");
}
}
else {
System.out.println("No frame found");
}

How can I switch WebDriver control between Frames?

If the application under test contains frames, then we need to switch the WebDriver control to that frame before interacting with the element inside the frame.


We can switch to frame either with it’s name/id or by specifying frame index.


Sample code : By using frame name


driver.switchTo().frame("frameName");

By index (Zero-based):


driver.switchTo().frame(1);

And to come back to default frame:

driver.switchTo().defaultContent();