在 Selenium WebDriver 中实现 InternetExplorerDriver 期间发生 NoSuchElementException

发布于 2024-12-03 02:51:12 字数 2317 浏览 0 评论 0原文

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

然而,如果我使用 Chrome 驱动程序或 Firefox 驱动程序,代码就可以正常工作。 任何想法或想法将不胜感激。

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)

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.

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

Code:

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

Error message:

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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

软的没边 2024-12-10 02:51:12

您已明确避免设置 IE 的保护模式设置。这就是 InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS 功能设置的作用。当您删除此功能设置并按照项目 wiki,看来问题自行解决了。

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.

囍笑 2024-12-10 02:51:12

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

WebDriver driver = new InternetExplorerDriver(ieCapabilities);
driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);

Try adding implicitly wait like below. Also as Robert said, your URL should have http://

WebDriver driver = new InternetExplorerDriver(ieCapabilities);
driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS);
悲喜皆因你 2024-12-10 02:51:12

有一个简短的 常见问题解答条目 (大约 Selenium 2.9 复制):

InternetExplorerDriver 要求设置所有安全域
相同的值(可信或不可信)如果您不在
修改安全域的位置,然后您可以覆盖
像这样检查:

所需能力能力 =
DesiredCapability.internetExplorer();
功能集(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
真的); 
WebDriver 驱动程序 = new InternetExplorerDriver(功能);

从常量的名称可以看出,这可能会导致不稳定
在你的测试中。如果所有站点都位于同一保护域中,则您
应该没问题。

并行 C# InvalidOperationException 消息:

启动 Internet Explorer 时出现意外错误。保护模式必须是
对于所有区域设置为相同的值(启用或禁用)。
(NoSuchDriver)

和 C# 而不是调整 IE 设置(截至 2016 年 2 月的最佳猜测):

var ieOptions = new OpenQA.Selenium.IE.InternetExplorerOptions {
                IntroduceInstabilityByIgnoringProtectedModeSettings = true };
using (var driver = new InternetExplorerDriver(ieOptions))
{

这都是 问题 1795追踪器。

There was a short FAQ entry on the project website (copied circa Selenium 2.9):

The InternetExplorerDriver requires that all security domains are set
to the same value (either trusted or untrusted) If you're not in a
position to modify the security domains, then you can override the
check like this:

DesiredCapabilities capabilities =
DesiredCapabilities.internetExplorer();
capabilities.set(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
true); 
WebDriver driver = new InternetExplorerDriver(capabilities);

As can be told by the name of the constant, this may introduce flakiness
in your tests. If all sites are in the same protection domain, you
should be okay.

The parallel C# InvalidOperationException message:

Unexpected error launching Internet Explorer. Protected Mode must be
set to the same value (enabled or disabled) for all zones.
(NoSuchDriver)

and the C# instead of adjusting IE settings (best guess as of Feb 2016):

var ieOptions = new OpenQA.Selenium.IE.InternetExplorerOptions {
                IntroduceInstabilityByIgnoringProtectedModeSettings = true };
using (var driver = new InternetExplorerDriver(ieOptions))
{

This was all part of issue 1795 on the Selenium issue tracker.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文