如何控制浏览器焦点?
我正在使用 C# webdriver 并试图弄清楚如何控制哪个浏览器处于焦点状态。
这基本上是我想做的
driver = StartBrowser();
driver1 = StartBrowser();
,然后切换回驱动程序,但我无法让它工作。
我知道这很简单,但我仍然无法让它工作:)。
这是我尝试过的不同版本:
driver.SwitchTo().Window(driver.CurrentWindowHandle);
I'm playing around with C# webdriver and trying to figure out how to control which browser is in focus.
This is basicly what i want do
driver = StartBrowser();
driver1 = StartBrowser();
and then switch back to driver, but i can't get it working.
I know it's prob really simple but i still can't get it working :).
This is what i tried different versions of:
driver.SwitchTo().Window(driver.CurrentWindowHandle);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SwitchTo
是改变单个驱动程序(浏览器)的上下文。当您有框架或弹出窗口并且您想告诉 selenium 在哪里查找元素时,可以使用此方法。如果您声明两个单独的驱动程序实例(根据您的示例),那么您将拥有两个独立的浏览器实例,其中每个实例都有自己的要搜索的上下文。从逻辑上讲,没有理由在它们之间切换,因为您可以使用相应的驱动程序变量来搜索每个浏览器。
SwitchTo
is to change the context of a single driver (browser). This is used when you have frames or pop up windows and you want to tell selenium where to look for elements.If you declare two separate driver instances (per your example) then you will have two independent browser instances where each will have its own context to search. There is logically no reason to switch between them because you can search each browser by using the corresponding driver variable.