Frames:
In HTML Frames are used to divide your browser window into multiple sections, where each section can load a separate HTML document. Frames are defined in the iframe tags (<iframe> </iframe>).
In HTML Frames are used to divide your browser window into multiple sections, where each section can load a separate HTML document. Frames are defined in the iframe tags (<iframe> </iframe>).
To handle frames in selenium we use the following methods
1. switch_to.frame()
2. switch_to.default_content()
3. switchTo_to.parent_frame()
1. switch_to.frame()
2. switch_to.default_content()
3. switchTo_to.parent_frame()
1. switch_to.frame():
When a web element is located in an iframe tag in that situation first we need to switch into that frame then only we can access that web element.
To change wed driver object from page level to frame level we will use the switch_to.frame() method.
We can access the frame by using the frame name, index and web element.
Syntax 1(Frame Name): driver.switch_to.frame(“frameName”)
Example: driver.switch_to_frame(“packageListFrame”)
Syntax 2(Index Number): driver.switch_to.frame(index number)
(Index value starts from 0 (Zero). The index of the First frame is zero (0), Index of the Second frame is one (1), like that we assign an index number to a frame method)
Example: driver.switch_to_frame(“packageListFrame”)
Syntax 2(Index Number): driver.switch_to.frame(index number)
(Index value starts from 0 (Zero). The index of the First frame is zero (0), Index of the Second frame is one (1), like that we assign an index number to a frame method)
Example: driver.switchTo().frame(0)
Syntax 3(Web Element): driver.switch_to.frame(WebElement);
Example:
wbe = driver.find_element(By.ID, “q”)
driver.switch_to_frame(wbe);
2. switch_to.default_content():
We can use this method to change the web driver object frame level to the page level.
wbe = driver.find_element(By.ID, “q”)
driver.switch_to_frame(wbe);
2. switch_to.default_content():
We can use this method to change the web driver object frame level to the page level.
Example/Syntax: driver.switch_to.default_content();
3. switch_to.parent_frame():
This method is used to change focus from the current frame to the parent frame (Exit from the current frame and enter the previous frame).
3. switch_to.parent_frame():
This method is used to change focus from the current frame to the parent frame (Exit from the current frame and enter the previous frame).
Example/Syntax: driver.switch_to.parent_frame();
No comments:
Post a Comment