首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在Selenium WebDriver中实现InternetExplorerDriver时发生NoSuchElementException

在Selenium WebDriver中实现InternetExplorerDriver时发生NoSuchElementException
EN

Stack Overflow用户
提问于 2011-09-02 09:15:23
回答 2查看 52.7K关注 0票数 16

目前,我正在使用WebDriver来调用IE浏览器来运行测试。但是当我尝试运行下面这个简单的例子时,我收到了一个NoSuchElementException

然而,如果我使用Chrome驱动程序或Firefox驱动程序,代码工作得很好。任何想法或想法都会受到感谢。

Jar:selenium-server-standalone-2.5.0.jar

代码:

代码语言:javascript
复制
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"));
}

错误消息:

代码语言:javascript
复制
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)
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2011-10-07 21:22:48

您已经明确避免了必须设置IE的保护模式设置。这就是InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS功能设置的作用。当您删除此功能设置并设置project wiki中记录的“保护模式”设置时,问题似乎会自行解决。

票数 14
EN

Stack Overflow用户

发布于 2011-09-03 21:14:40

尝试像下面这样隐式添加等待。同样,正如Robert所说,您的URL应该包含http://

代码语言:javascript
复制
WebDriver driver = new InternetExplorerDriver(ieCapabilities);
driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7278340

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档