gpt4 book ai didi

java - 使用 IntelliJ IDEA IDE 进行 Selenium 自动化打开 IE 9 时出现错误

转载 作者:行者123 更新时间:2023-12-02 00:01:34 25 4
gpt4 key购买 nike

我的代码是:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class Example
{
public static void main(String[] a)
{
WebDriver driver = new InternetExplorerDriver() ;
System.setProperty("sun.net.spi.nameservice.provider.1", "dns,sun");
driver.navigate();
driver.get("http://www.google.com/");
System.out.println("Page title is: " + driver.getTitle());
}
}

出现错误:

WARNING: This method of starting the IE driver is deprecated and will be removed in selenium 2.26. Please download the IEDriverServer.exe from http://code.google.com/p/selenium/downloads/list and ensure that it is in your PATH.
Exception in thread "main" org.openqa.selenium.WebDriverException: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode must be set to the same value (enabled or disabled) for all zones. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 289 milliseconds
Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 21:09:54'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.7.0_13'
Driver info: driver.version: InternetExplorerDriver
Session ID: 0521cc95-3fbb-43c8-9073-7602d937450b
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:188)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:498)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:182)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:167)
at org.openqa.selenium.ie.InternetExplorerDriver.startSession(InternetExplorerDriver.java:133)
at org.openqa.selenium.ie.InternetExplorerDriver.setup(InternetExplorerDriver.java:106)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:52)
at Example.main(Example.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

Process finished with exit code 1

我不知道出了什么问题。

最佳答案

警告说明您应该做什么:

警告:这种启动 IE 驱动程序的方法已被弃用,并将在 selenium 2.26 中删除。请从http://code.google.com/p/selenium/downloads/list下载IEDriverServer.exe并确保它在您的路径中。

因此,首先,从 http://code.google.com/p/selenium/downloads/list 下载 IEDriverServer.exe

启动 IE 驱动程序的正确方法是:

System.setProperty("webdriver.ie.driver", "path/to/ IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver() ;

关于java - 使用 IntelliJ IDEA IDE 进行 Selenium 自动化打开 IE 9 时出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14725797/

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