gpt4 book ai didi

java - 在 Selenium WebDriver 中执行 InternetExplorerDriver 时发生 NoSuchElementException

转载 作者:太空狗 更新时间:2023-10-29 22:45:49 24 4
gpt4 key购买 nike

目前,我正在开发 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)

最佳答案

您已明确避免必须设置 IE 的保护模式设置。这就是 InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS 功能设置的作用。当您删除此功能设置并设置保护模式设置时,如 project wiki 中所述, 看来问题自行解决了。

关于java - 在 Selenium WebDriver 中执行 InternetExplorerDriver 时发生 NoSuchElementException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7278340/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com