简体   繁体   English

使用Internet Explorer驱动程序无法在Selenium中找到任何元素

[英]Cannot find any elements in Selenium using Internet Explorer Driver

I cannot get Selenium to identify any elements with Internet Explorer Driver regardless of the page used or the selection type. 无论使用什么页面或选择哪种类型,我都无法让Selenium使用Internet Explorer驱动程序识别任何元素。

String iedriver = "C:\\selenium-server\\IEDriverServer.exe";
System.setProperty("webdriver.ie.driver", iedriver);
WebDriver driver = new InternetExplorerDriver();
driver.get("http://www.google.com");
WebElement element = driver.findElement(By.xpath("//body"));

Selecting by xpath gives org.openqa.selenium.InvalidSelectorException: The xpath expression '//body' cannot be evaluated or does notresult in a WebElement. 通过xpath进行选择会产生org.openqa.selenium.InvalidSelectorException:无法评估xpath表达式'// body'或不会导致WebElement。 Other selection types also fail: 其他选择类型也将失败:

WebElement element = driver.findElement(By.cssSelector("body"));

or 要么

WebElement element = driver.findElement(By.tagName("body"));

or 要么

 WebElement element = driver.findElement(By.name("q"));

By CSS Selector, Name, or Tag Name always results in org.openqa.selenium.NoSuchElementException 通过CSS选择器,名称或标记名始终会导致org.openqa.selenium.NoSuchElementException

All selections work perfectly fine with Firefox Driver, Chrome Driver, and even Html Unit Driver. 所有选择都可以与Firefox驱动程序,Chrome驱动程序甚至HTML单位驱动程序完美配合。

The browser correctly starts and the page loads as expected. 浏览器正确启动,页面按预期加载。 driver.getCurrentUrl(); driver.getCurrentUrl(); and driver.getPageSource(); driver.getPageSource(); return the expected values. 返回期望值。

I tried introducing explicit and implicit waits before selecting an element but to no effect, using 我尝试在选择元素之前引入显式和隐式等待,但没有效果,使用

Thread.sleep(10000); 

or 要么

WebDriverWait(driver,60).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//body")));

Also tried stepping through the code to manually wait for elements to be displayed. 还尝试单步执行代码以手动等待元素显示。

Other things I tried included 1) setting the security settings to the same level in all zones 2) disabling Enhanced Protected Mode 3) setting the FEATURE_BFCACHE in the registery 我尝试过的其他操作包括1)在所有区域中将安全设置都设置为相同级别2)禁用增强保护模式3)在注册表中设置FEATURE_BFCACHE

I am using Selenium and IEDriverServer versions 2.41. 我正在使用Selenium和IEDriverServer 2.41版。 The problem is observed running both locally and remotely. 观察到该问题在本地和远程运行。 The environment is on Windows 7 64-bit using IE10 64-bit and IEDriverServer 64-bit. 该环境在使用IE10 64位和IEDriverServer 64位的Windows 7 64位上。 The same problem was observed on IE11 32-bit using IEDriverServer 32-bit. 使用32位IEDriverServer在IE11 32位上也观察到相同的问题。 I used www.google.com here as a publicly viewable test but the problem is also observed on our internal site. 我在这里使用www.google.com作为可公开查看的测试,但是在我们的内部网站上也发现了该问题。

For those experiencing the issue on IE11, here is why: Microsoft released update KB3025390 via Windows Update[1] as part of its normal "patch Tuesday" update cycle. 对于那些在IE11上遇到问题的人,原因如下:Microsoft通过Windows Update [1]发布了更新KB3025390,这是其正常的“星期二补丁程序”更新周期的一部分。 For most users, this update is downloaded and installed without user interaction. 对于大多数用户,无需用户交互即可下载和安装此更新。 This update breaks the IE driver when using it with IE11. 与IE11一起使用时,此更新会破坏IE驱动程序。

https://groups.google.com/forum/m/#!topic/selenium-users/TdY_rRNF-gw https://groups.google.com/forum/m/#!topic/selenium-users/TdY_rRNF-gw

The fix, remove the update. 修复后,删除更新。 There is no Selenium update right now to workaround the issue. 目前没有Selenium更新可解决此问题。

通过将Internet区域中“ Internet选项”中的安全级别从“高”降低到“中高”或“中”,我能够解决此问题。

What worked for me was the solution noted at the bottom of this page: Running local HTML pages 对我有用的是在页面底部指出的解决方案: 运行本地HTML页面

To fix this, please go to "Internet options" in the Tools menu (or the gear icon in newer versions). 要解决此问题,请转到“工具”菜单中的“ Internet选项”(或在较新版本中使用齿轮图标)。 Open the Advanced tab. 打开高级选项卡。 Scroll down to "Security" and select "Allow active content to run in files on My Computer". 向下滚动到“安全”,然后选择“允许活动内容在我的电脑上的文件中运行”。

A reboot was then required. 然后需要重新启动。

if you run your IDE in admin mode before running the test, it will solve the problem. 如果在运行测试之前以管理模式运行IDE,它将解决问题。 Ensure the IDE is running with admin rights. 确保IDE以管理员权限运行。

Go to IE settings> Security tab> Disable Protected mode for all zones. 转到所有区域的IE设置>安全选项卡>禁用保护模式。 this activity fixed my problem. 这项活动解决了我的问题。

I had problems accessing multiple elements asynchronous. 我在异步访问多个元素时遇到问题。 Putting them in an async function and writing "await" before each statement solved it for me. 将它们放在异步函数中并在每个语句为我解决该问题之前写“ await”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM