What is the difference between defaultcontent() and Parentframe() method in selenium webDriver?


What is the difference between defaultcontent() and Parentframe() method in selenium webDriver?



What is difference between below two methods :


driver.switchTo().parentFrame();
driver.switchTo().defaultContent();




3 Answers
3



As per the specifications, driver.switchTo().parentFrame(); invokes the following:


driver.switchTo().parentFrame();



Switch To Parent Frame



Where, the Switch to Parent Frame command sets the current browsing context for future commands to the parent of the current browsing context.



As per the Java Docs parentFrame() method changes the focus to the parent context. If the current context is the top level browsing context, the context remains unchanged.



As per the Java Docs, defaultContent() method selects either the first frame on the page, or the main document when a page contains iframes.





That mean for example If i have 3 frames which are nested frames i1, i2, i3. If my cursor currently in i3. By using parentframe() i can reach to i2 and i can reach to i1 by using defaultcontent()
– sreenath reddy
2 days ago






@sreenathreddy Correct If my cursor currently in i3. By using parentframe() i can reach to i2 but defaultcontent() will take you to the main document i.e. Top-level browsing context
– DebanjanB
2 days ago


If my cursor currently in i3. By using parentframe() i can reach to i2


defaultcontent()



There is clearly a difference :



Scenario : When there are multiple frames and some of them are nested.



iframeMain
iframeParent
iframechild



Assume you are in ifrmaechild :



When you do driver.switchTo().parentFrame(); : you will go to iframeParent .
But when you do driver.switchTo().defaultContent(); : you will go to main HTML of page.
Note that in this case you will not go to iframeMain .


driver.switchTo().parentFrame();


driver.switchTo().defaultContent();



When you are dealing with multiple iframes in your webpage, then driver.switchTo().parentFrame() is generally used to switch the control back to the parent frame.


driver.switchTo().parentFrame()



When you deal with pop-up dialog windows within your webpage, then driver.switchTo().defaultContent() is used to switch the control back to default content in the window.


driver.switchTo().defaultContent()






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Opening a url is failing in Swift

Export result set on Dbeaver to CSV