java selenium ie_java – Selenium没有检测到IE中的第二个窗口

在处理InternetExplorer时,您需要注意以下几点:

正如您所提到的,github中记录了selenium的已知问题,这些问题不是问题,而是处理InternetExplorer时的Required Configuration组合.如果不考虑这些设置,InternetExplorer可能不会按预期运行.以下各项对于演示InternetExplorer v11的正确行为至关重要:

>对于IE 10及更高版本,必须禁用增强保护模式.此选项位于“Internet选项”对话框的“高级”选项卡中.

>浏览器缩放级别必须设置为100%,以便可以将本机鼠标事件设置为正确的坐标.

>您必须在显示设置中将文本,应用和其他项目的大小更改为100%.

>对于IE 11,您需要在目标计算机上设置一个注册表项,以便驱动程序可以维护与其创建的Internet Explorer实例的连接.

For 32-bit Windows installations, the key you have to look in the registry is :

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE

For 64-bit Windows installations, the key is :

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE

The FEATURE_BFCACHE subkey may or may not be present, and should be created if it is not present.

> Native Events:使用本机事件的优势在于它不依赖于JavaScript沙箱,并确保在浏览器中正确传播JavaScript事件.但是,当IE浏览器窗口没有焦点,以及尝试将鼠标悬停在元素上时,鼠标事件目前存在一些问题.

> Browser Focus:如果窗口没有焦点,IE本身似乎不完全尊重我们发送IE浏览器窗口(WM_MOUSEDOWN和WM_MOUSEUP)的Windows消息.

>您可以找到有关Native Events和Browser Focus here的详细讨论.

>现在,您必须通过DesiredCapabilities类配置所有这些参数,如下所示:

DesiredCapabilities cap = DesiredCapabilities.internetExplorer();

cap.setCapability("ignoreProtectedModeSettings",1);

cap.setCapability("IntroduceInstabilityByIgnoringProtectedModeSettings",true);

cap.setCapability("nativeEvents",true);

cap.setCapability("browserFocus",true);

cap.setCapability("ignoreZoomSetting", true);

cap.setCapability("requireWindowFocus","true");

cap.setCapability("INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS", true);

>根据最佳编程实践Thread.sleep(1000);是一个巨大的否,因为它降低了测试性能

>现在,您知道浏览器客户端滞后于WebDriver实例,因此我们必须经常同步它们.因此,在收集windowHandles之前,您必须按如下方式引导WebDriverWait,您可以在其中找到detailed discussion here:

WebElement popup= driver.findElement(By.name("popup"));

popup.click();

new WebDriverWait(driver,5).until(ExpectedConditions.numberOfWindowsToBe(2));

Set windowHandles = driver.getWindowHandles();

System.out.println(windowHandles);

更新

我可以从你的评论中看到:

"Enable Enhanced Protected Mode" is unchecked in IE options. – Renjith Jan 9 at 7:26

以下是@JimEvans sensetional博客于Protected Mode settings and the Capabilities hack发表的文章,其中@JimEvans以清晰明确的术语指出了背景:

When the rewritten IE driver was first introduced, it was decided that it would enforce its required Protected Mode settings, and throw an exception if they were not properly set. Protected Mode settings, like almost all other settings of IE, are stored in the Windows registry, and are checked when the browser is instantiated. However, some misguided IT departments make it impossible for developers and testers to set even the most basic settings on their machines.

The driver needed a workaround for people who couldn’t set those IE settings because their machine was overly locked down. That’s what the capability setting is intended to be used for. It simply bypasses the registry check. Using the capability doesn’t solve the underlying problem though. If a Protected Mode boundary is crossed, very unexpected behavior including hangs, element location not working, and clicks not being propagated, could result. To help warn people of this potential problem, the capability was given big scary-sounding names like INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS in Java and IntroduceInstabilityByIgnoringProtectedModeSettings in .NET. We really thought that telling the user that using this setting would introduce potential badness in their code would discourage its use, but it turned out not to be so.

If you are able to set the Protected Mode settings of IE, and you are still using the capability you are risking the stability of your code. Don’t do it. Set the settings. It’s not that hard.

以下是设置保护模式设置的方法:

UMweq.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值