What is the difference between driver.switchTo().p

2020-06-23 09:27发布

What is difference between below two methods :

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

4条回答
Rolldiameter
2楼-- · 2020-06-23 10:03

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 .

查看更多
叼着烟拽天下
3楼-- · 2020-06-23 10:05

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.

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.

查看更多
放荡不羁爱自由
4楼-- · 2020-06-23 10:13

driver.switchTo().parentFrame();

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

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.

driver.switchTo().defaultContent();

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

查看更多
趁早两清
5楼-- · 2020-06-23 10:22

driver.switchTo().defaultContent();

This will pass the control to the main document which contains the iframes

driver.switchTo().parentFrame();

This will pass the control to the imminent parent frame of the current frame

Lets understand it:

main body
{
frame1
{
frame2
frame3 (we are here currently)
}
}

Now using driver.switchTo().defaultContent(); will pass the control to main body

And using driver.switchTo().parentFrame(); will pass the control to frame1 .

查看更多
登录 后发表回答