WebDriver.SwitchTo().Window()和WebDriver.SwitchTo().Frame()有什么区别 [英] What is the difference between WebDriver.SwitchTo().Window() and WebDriver.SwitchTo().Frame()

查看:171
本文介绍了WebDriver.SwitchTo().Window()和WebDriver.SwitchTo().Frame()有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天前,我需要在浏览器的2个标签之间切换 WebDriver (在这种情况下为Chromedriver)(其中一个通过单击链接自动打开).

A few days ago, I had the requirement to make my WebDriver(Chromedriver in that case) switch between 2 tabs on my browser (One of which has been automatically opened by clicking a link).

我能够使用以下几行( C#)

I was able to implement a solution using the following lines (C#)

var tabs = new List<String>(Driver.WindowHandles);
//Switches to the first tab
Driver.SwitchTo().Window(tabs[0]);

但是,我最近遇到了一些使用框架和警报的实现,这使我感到困惑.

However, I recently came across some implementations that use frames and alerts, which confused me.

文档对我不是很有帮助,因为我仍然遇到麻烦找出每种情况的用例.

The documentation has not been very helpful to me as I still have trouble figuring out use cases for each.

请问我 Frame Window 的区别是什么(性能,可靠性,跨平台...)?

Could you please enlighten me what the difference between Frame and Window is for that purpose ( performance, reliability, cross-platform,... )?

推荐答案

框架:

HTML 中的标记.但是,HTML5不支持该标记.

is a tag in HTML. However The tag is not supported in HTML5.

< frame >标记定义了<frameset>

The <frame> tag defines one particular window (frame) within a <frameset>

通常,您必须已经在 DOM 中看到了 iframe .它基本上是HTML页面的一部分.

Normally, You must have seen Iframe in DOM. It's basically section of a HTML page.

此外,如果要与框架内的任何元素进行交互,则必须切换到框架.

Moreover, If you want to interact any element which is inside a frame , You will have to switch to frame.

方法:

SwitchTo().Frame(int frameIndex):使用索引

SwitchTo().Frame(IWebElement frameElement):使用其先前位于的OpenQA.Selenium.IWebElement选择一个框架.

SwitchTo().Frame(IWebElement frameElement) : Select a frame using its previously located OpenQA.Selenium.IWebElement.

SwitchTo().Frame(string frameName):根据其名称选择一个框架.

SwitchTo().Frame(string frameName) : Select a frame by its name.

Windows:

当您单击任何链接时,将打开一个新标签页或一个新窗口本身,这是Selenium中的一个窗口.

When you click on any any link and a new tab opens or a new windows itself open that's a window in Selenium.

方法:您已经在帖子中提到了这一点.

How : You have already mentioned that in your Post.

希望这会有所帮助.

这篇关于WebDriver.SwitchTo().Window()和WebDriver.SwitchTo().Frame()有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆