java – Selenium没有检测到IE中的第二个窗口
我的应用程序打开一个单击按钮的新窗口,我需要在该窗口中执行一些操作.但是selenium webdriver的响应getWindowHandles()方法只有一个窗口id.如果在打开新窗口后调用getWindowHandles()有延迟,则会发生这种情况.硒存在已知问题.
https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration 但即使是解决方案也不适用于我. 代码如下 DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),capabilities); driver.get("https://<url>"); WebElement userName = driver.findElement(By.name("usr_name")); userName.sendKeys("ABCD"); WebElement password = driver.findElement(By.name("usr_password")); password.sendKeys("password"); WebElement login = driver.findElement(By.name("OK")); login.click(); WebElement popup= driver.findElement(By.name("popup")); popup.click(); Thread.sleep(1000); Set<String> windowHandles = driver.getWindowHandles(); System.out.println(windowHandles); Set“windowHandles”将只返回一个窗口: "[fcdad457-9090-4dfd-8da1-acb9d6f73f74]" 但如果我取消睡眠.它将返回两个窗口ID: [90cc6006-0679-450c-a5b3-6602bcb41a16,7211bbfd-2616-4460-97e7-56c0e632c3bb] 我无法移除睡眠,因为这只是一个示例程序,在实际应用程序中,它们之间会有一些延迟.请让我知道你的想法.这个问题仅适用于IE11. 蓝屏 – 主页; 解决方法
在处理InternetExplorer时,您需要注意以下几点:
正如您所提到的,github中记录了selenium的已知问题,这些问题不是问题,而是处理InternetExplorer时的 >对于IE 10及更高版本,必须禁用增强保护模式.此选项位于“Internet选项”对话框的“高级”选项卡中. For 32-bit Windows installations,the key you have to look in the registry is : HKEY_LOCAL_MACHINESOFTWAREMicrosoftInternet ExplorerMainFeatureControlFEATURE_BFCACHE For 64-bit Windows installations,the key is : HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftInternet ExplorerMainFeatureControlFEATURE_BFCACHE The FEATURE_BFCACHE subkey may or may not be present,and should be created if it is not present. > 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);是一个巨大的否,因为它降低了测试性能 WebElement popup= driver.findElement(By.name("popup")); popup.click(); new WebDriverWait(driver,5).until(ExpectedConditions.numberOfWindowsToBe(2)); Set<String> windowHandles = driver.getWindowHandles(); System.out.println(windowHandles); 更新 我可以从你的评论中看到: "Enable Enhanced Protected Mode" is unchecked in IE options. – Renjith Jan 9 at 7:26 以下是@JimEvans sensetional博客于
以下是设置保护模式设置的方法: >这是 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |