在 Selenium WebDriver 中实现 InternetExplorerDriver 时发生 NoSuchElementException [英] NoSuchElementException is occurred during implementation of InternetExplorerDriver in Selenium WebDriver
问题描述
目前,我正在使用 WebDriver 来调用 IE 浏览器来运行测试.但是当我尝试运行下面的简单示例时,我收到了 NoSuchElementException
.
Currently, I am working on WebDriver to invoke IE browser to run the testing. But I received a NoSuchElementException
when I tried to run the simple example below.
但是,如果我使用 Chrome 驱动程序或 Firefox 驱动程序,代码就可以正常工作.任何想法或想法将不胜感激.
However, the code just worked fine if I used Chrome Driver or Firefox driver. Any idea or thought would be appreciated.
jar:selenium-server-standalone-2.5.0.jar
代码:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public static void main(String[] args) throws InterruptedException {
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
WebDriver driver = new InternetExplorerDriver(ieCapabilities);
driver.get("www.google.com");
driver.findElement(By.name("q"));
}
错误信息:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with name == q (WARNING: The server did not provide any stacktrace information)
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.5.0', revision: '13516', time: '2011-08-23 18:29:57'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_25'
Driver info: driver.version: RemoteWebDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:131)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:105)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:409)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:197)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByName(RemoteWebDriver.java:246)
at org.openqa.selenium.By$ByName.findElement(By.java:298)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:189)
at lib.WebDriver2.main(WebDriver2.java:14)
推荐答案
您已经明确避免了必须设置 IE 的保护模式设置.这就是 InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS
功能设置的作用.当您删除此功能设置并按照 项目维基,看来问题自己解决了.
You've explicitly avoided having to set the Protected Mode settings of IE. That's what the InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS
capability setting does. When you remove this capability setting and set the Protected Mode settings as documented in the project wiki, it seems the problem resolves itself.
这篇关于在 Selenium WebDriver 中实现 InternetExplorerDriver 时发生 NoSuchElementException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!