I'd like to mention few important things regarding switching and toggling between frames :
i) If the frame is at same level we can't jump between the frames while we are already on frames. Suppose 2 frames frame1 and frame2 are popped on a button click. We used switchTo() method to switch to the frame1. Now we want to switch to frame2. This is not possible since we are on frame1 and both the frames are at same level. We will get NoSuchFrame Exception if we try to switch to frame2 if we are on frame 1 and both the frames are at same level.
Here we need to switch back to the parent window or frame by using defaultcontent()/parentFrame() then again we can use swichTo() to switch to second frame.
2) If frames are at multiple levels then we can use switchTo() method to switch between multiple frames. Suppose we click on button and frame1 is generated. Now we click on a button on frame1 then frame 2 is generated. If we click on a button on frame 2 then frame3 is generated and if click on button on frame3 then a new frame frame4 is generated.
In this scenario if we want to switch to frame 4 we need to switch to multi level frames :
-> use switchTo() to switch to frame1
-> When you are on frame 1, use switchTo() to switch to frame 2
-> When you are on frame 2, use switchTo() to switch to frame 3
-> When you are on frame 3, use switchTo() to switch to frame 4
In this way we can switch between the frames at multi and single levels
Now the question arises , How to switch back to the initial frames?
To answer this I'd like to include 2 methods defaultContent() and parentFrame().
->defaultContent() - This method will allow you to switch to the initial or very first window from where the frames were generated.
->parentFrame() - This method will allow you to switch to the immediate parent frame in case of multi level frames. As discussed above in scenario 2 if we want to switch from frame2 to frame1 or frame3 to frame 2 we can use this method. If we are on frame2 and use switchTo().parentFrame(), it will switch to the frame1.
i) If the frame is at same level we can't jump between the frames while we are already on frames. Suppose 2 frames frame1 and frame2 are popped on a button click. We used switchTo() method to switch to the frame1. Now we want to switch to frame2. This is not possible since we are on frame1 and both the frames are at same level. We will get NoSuchFrame Exception if we try to switch to frame2 if we are on frame 1 and both the frames are at same level.
Here we need to switch back to the parent window or frame by using defaultcontent()/parentFrame() then again we can use swichTo() to switch to second frame.
2) If frames are at multiple levels then we can use switchTo() method to switch between multiple frames. Suppose we click on button and frame1 is generated. Now we click on a button on frame1 then frame 2 is generated. If we click on a button on frame 2 then frame3 is generated and if click on button on frame3 then a new frame frame4 is generated.
In this scenario if we want to switch to frame 4 we need to switch to multi level frames :
-> use switchTo() to switch to frame1
-> When you are on frame 1, use switchTo() to switch to frame 2
-> When you are on frame 2, use switchTo() to switch to frame 3
-> When you are on frame 3, use switchTo() to switch to frame 4
In this way we can switch between the frames at multi and single levels
Now the question arises , How to switch back to the initial frames?
To answer this I'd like to include 2 methods defaultContent() and parentFrame().
->defaultContent() - This method will allow you to switch to the initial or very first window from where the frames were generated.
->parentFrame() - This method will allow you to switch to the immediate parent frame in case of multi level frames. As discussed above in scenario 2 if we want to switch from frame2 to frame1 or frame3 to frame 2 we can use this method. If we are on frame2 and use switchTo().parentFrame(), it will switch to the frame1.
No comments:
Post a Comment