【发布时间】:2014-05-20 22:13:01
【问题描述】:
无论使用的页面或选择类型如何,我都无法让 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"));
通过 xpath 选择会导致 org.openqa.selenium.InvalidSelectorException: xpath 表达式“//body”无法评估或不会生成 WebElement。其他选择类型也失败:
WebElement element = driver.findElement(By.cssSelector("body"));
或
WebElement element = driver.findElement(By.tagName("body"));
或
WebElement element = driver.findElement(By.name("q"));
按 CSS 选择器、名称或标记名称总是导致 org.openqa.selenium.NoSuchElementException
所有选择都可以与 Firefox 驱动程序、Chrome 驱动程序甚至 Html 单元驱动程序完美配合。
浏览器正确启动,页面按预期加载。 driver.getCurrentUrl(); 和 driver.getPageSource(); 返回预期值。
我尝试在选择元素之前引入显式和隐式等待,但没有效果,使用
Thread.sleep(10000);
或
WebDriverWait(driver,60).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//body")));
还尝试单步执行代码以手动等待元素显示。
我尝试过的其他事情包括 1) 在所有区域中将安全设置设置为相同级别 2) 禁用增强保护模式 3) 在注册表中设置 FEATURE_BFCACHE
我正在使用 Selenium 和 IEDriverServer 2.41 版。观察到该问题在本地和远程运行。该环境在使用 IE10 64 位和 IEDriverServer 64 位的 Windows 7 64 位上。在使用 IEDriverServer 32 位的 IE11 32 位上观察到同样的问题。我在这里使用 www.google.com 作为公开可见的测试,但在我们的内部网站上也发现了这个问题。
【问题讨论】:
-
无需设置“所有区域的安全设置为同一级别”。但是,有必要在所有区域中将Protected Mode settings 设置为相同的值。
-
这是一个很好的建议,但我已经将保护模式全部设置为相同的设置。我尝试了所有启用和未启用保护模式的区域。
-
我什至尝试使用 INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS 但没有任何区别。
-
非常感谢您的提问:)
标签: internet-explorer selenium-webdriver