About Frames :
1) We can get the count of all the frames available on a page by :
Int size = driver.findElements(By.tagName("iframe")).size();
2) To go to a particular frame we use switchTo() method in webdriver
driver.switchTo().frame(0);
3) There are 4 ways of locating a frame :
By frame ID : driver.switchTo().frame("frameID");
By frame Name : driver.switchTo().frame("frame name");
By frame Index: driver.switchTo().frame(0);
By frame Webelement : driver.switchTo().frame(WebElement);
4) Parentframe() is used to switch to immediate parent of frame
defaultcontent() is used to switch to initial frame.
5) Handling multiple frames:
i) If all the frames are ar same node/level : In this scenario we will have to return back to the parent of node or default node as applicable . After that we need to switch to another frame.
ii) If the frames are present in node and another frame is in the child of parent frame node : In this case we can use switchTo() to switch to the first frame and then again we can use switchTo() to switch to inner frames
Note : frame to frame switching is only possible is one frame is the child of the main frame
6) If any element is on frame and we are trying to locate it directly(without switching to frame) , then it will give NoSuchElementException
7) If invalid locator is given to locate a frame then NoSuchFrameException will hit.
1) We can get the count of all the frames available on a page by :
Int size = driver.findElements(By.tagName("iframe")).size();
2) To go to a particular frame we use switchTo() method in webdriver
driver.switchTo().frame(0);
3) There are 4 ways of locating a frame :
By frame ID : driver.switchTo().frame("frameID");
By frame Name : driver.switchTo().frame("frame name");
By frame Index: driver.switchTo().frame(0);
By frame Webelement : driver.switchTo().frame(WebElement);
4) Parentframe() is used to switch to immediate parent of frame
defaultcontent() is used to switch to initial frame.
5) Handling multiple frames:
i) If all the frames are ar same node/level : In this scenario we will have to return back to the parent of node or default node as applicable . After that we need to switch to another frame.
ii) If the frames are present in node and another frame is in the child of parent frame node : In this case we can use switchTo() to switch to the first frame and then again we can use switchTo() to switch to inner frames
Note : frame to frame switching is only possible is one frame is the child of the main frame
6) If any element is on frame and we are trying to locate it directly(without switching to frame) , then it will give NoSuchElementException
7) If invalid locator is given to locate a frame then NoSuchFrameException will hit.
No comments:
Post a Comment