C#IE11 selenium webdriver,没有新选项卡的新窗口句柄 [英] C# IE11 selenium webdriver, No new window handles with new tab

查看:710
本文介绍了C#IE11 selenium webdriver,没有新选项卡的新窗口句柄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的应用程序打开一个新选项卡时,Internet Explorer 11的Selenium Webdriver没有创建新的窗口句柄。

Selenium Webdriver for Internet Explorer 11 is not creating a new window handle when my app opens a new tab.

问题类似于这个,这是窗口句柄在几分之一秒内消失的问题,但在我的情况下,首先甚至没有创建新的窗口句柄。

The problem is similar to this , which was a problem with the window handles disappearing in a fraction of a second, but in my case a new window handle isn't even created in the first place.

我使用该链接中的测试代码来检查消失的窗口句柄,但它从来没有在打开新选项卡时创建另一个窗口句柄,因此测试只显示第一个控制台输出而不显示第二个部分。

I used the test code from that link to check for disappearing window handles, but it never created another window handle when a new tab was opened, so the test only displayed the first console output and never the second part.

我尝试使用:

driver.SwitchTo().Window(driver.WindowHandles.Last());

但是Selenium Webdriver焦点停留在第一个标签上,因为我认为它不会创建新的处理新标签。

but the Selenium Webdriver focus stays on the first tab, because I believe it isn't creating a new handle for the new tab.

此外,试过这个:

driver.SwitchTo().Window(driver.WindowHandles[1]);

这会导致超出范围的异常并且指数超出范围。必须是非负的且小于集合的大小。

and that results in an "out of range" exception and "Index was out of range. Must be non-negative and less than the size of the collection."

如果我将[1]更改为[0],那么显然我没有得到异常,因为焦点只设置为第一个选项卡。

If I change the [1] to a [0], then obviously I do not get the exception because the focus is just set to the first tab.

根据我在测试代码中测试我提供的链接以及我自己的尝试,我相信新的窗口句柄是没有被创建。

Based on my testing with the test code in the link I provided and my own attempts, I believe that new window handles are not being created.

我尝试重置IE11,然后只更改Selenium网站上描述的设置,包括添加注册表项,我使用了Helium的解决方案找到了这里

I tried resetting IE11 and then only changing the settings as described on Selenium's website including adding the registry key, which I used Helium's solution to that found here.

另外,我读了一些建议将我打开的网站添加到IE中的可信站点列表中,但仍然没有。

Also, I read some suggestions of adding the websites that I am opening to the Trusted sites list in IE, but still no go.

任何帮助表示赞赏。谢谢。

Any help is appreciated. Thanks.

推荐答案

这是我设法使用的解决方法。

Here's a workaround I managed to use.

您可以使用javascript打开一个新窗口。它会给你提供句柄。

You can use javascript to open a new window. It will give you the handle.

string javaScript = "window.open('" + url + "','_blank', 'resizable=yes, scrollbars=yes, titlebar=yes, width=1280, height=680, top=10, left=10');";

jsExecutor = (IJavaScriptExecutor)ieDriver;
jsExecutor.ExecuteScript(javaScript);

这篇关于C#IE11 selenium webdriver,没有新选项卡的新窗口句柄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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