使用Internet Explorer驱动程序在Selenium中找不到任何元素 [英] Cannot find any elements in Selenium using Internet Explorer Driver

查看:466
本文介绍了使用Internet Explorer驱动程序在Selenium中找不到任何元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论使用哪个页面或选择类型,我都无法通过Internet Explorer驱动程序识别任何元素。

I cannot get Selenium to identify any elements with Internet Explorer Driver regardless of the page used or the selection type.

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"));

通过xpath选择提供 org.openqa.selenium.InvalidSelectorException: xpath表达式'// body'无法在WebElement中进行评估或不进行评估。其他选择类型也会失败:

Selecting by xpath gives org.openqa.selenium.InvalidSelectorException: The xpath expression '//body' cannot be evaluated or does notresult in a WebElement. Other selection types also fail:

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

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

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

通过CSS Selector,Name或Tag Name始终生成 org.openqa.selenium。 NoSuchElementException

By CSS Selector, Name, or Tag Name always results in org.openqa.selenium.NoSuchElementException

所有选项都适用于Firefox驱动程序,Chrome驱动程序甚至Html单元驱动程序。

All selections work perfectly fine with Firefox Driver, Chrome Driver, and even Html Unit Driver.

浏览器正确启动,页面按预期加载。 driver.getCurrentUrl(); driver.getPageSource(); 返回预期值。

The browser correctly starts and the page loads as expected. driver.getCurrentUrl(); and 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); 

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

还尝试单步执行代码以手动等待元素显示。

Also tried stepping through the code to manually wait for elements to be displayed.

我尝试过的其他事项包括:1)在所有区域中将安全设置设置为相同级别2)禁用增强保护模式3)在注册表中设置FEATURE_BFCACHE

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

我使用的是Selenium和IEDriverServer版本2.41。观察到本地和远程运行的问题。环境在Windows 7 64位上使用IE10 64位和IEDriverServer 64位。使用IEDriverServer 32位在IE11 32位上观察到同样的问题。我在这里使用www.google.com作为可公开查看的测试,但问题也出现在我们的内部网站上。

I am using Selenium and IEDriverServer versions 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. The same problem was observed on IE11 32-bit using IEDriverServer 32-bit. I used www.google.com here as a publicly viewable test but the problem is also observed on our internal site.

推荐答案

我能够通过降低Internet区域中Internet选项中的安全级别来解决问题到中高或中等。

I was able to solve the problem by lowering the the security level in "Internet Options" in the Internet zone from "High" to "Medium-high" or "Medium".

这篇关于使用Internet Explorer驱动程序在Selenium中找不到任何元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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