0

我的代码是:

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

我不知道怎么了。

4

2 回答 2

2

警告说你应该怎么做:

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

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

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

System.setProperty("webdriver.ie.driver", "path/to/ IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver() ;
于 2013-02-06T09:46:23.273 回答
1

您使用的是旧版本的 Selenium 和 IEDriver。

从这里下载最新版本的 SeleniumIEDriverServer:

https://code.google.com/p/selenium/downloads/list

于 2013-02-06T09:46:54.350 回答