Frames is the html document which is embedded on another html document.So page on the page is frames.Generally Frames are used in web page when there are dynamic changes in webpage.Instead of loading whole webpage only frame are loaded.
Ex: Breaking news in news webpage.
How to Automate Frames:
Example 1:
When we are dealing with frames we have use switchTo() to Frame() method.
Syntax: driver.switchTo().frame();
Here in above image we have show you how to switch from frame1 to frame2 when two frame are different.
Step 1:
First driver focus will be on normal webpage,So we have to switch from webpage to Frame1.
driver.switchTo.frame("frame1");
Step 2:
Now the driver focus is on frame1.if we want to switch from frame1 to frame2 then we have to switch to default content i,e webpage.
driver.switchTo.defaultcontent();
Step3:
Now the focus is on webpage again we have to switch from webpage to Frame2 now.
driver.switchTo.frame("frame2");
Example 2:
Here in above image we have show you how to switch from frame1 to frame2 when two frame are embedded.that means frame within frame. So in this case steps would be.
Step 1:
First driver focus will be on normal webpage,So we have to switch from webpage to Frame1.
driver.switchTo.frame("frame1");
Step 2:
Now the driver focus is on frame1.if we want to switch from frame1 to frame2 then we can directly switch to frame2. In this case no need to switch to default page (or) Normal webpage.
driver.switchTo.frame("frame2");
Example:
No comments:
Post a Comment