使用selenium启动IE - 错误

时间:2014-02-19 08:29:31

标签: java eclipse selenium selenium-webdriver

我正在尝试使用Selenium在以下代码的帮助下打开IE:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;


public class seleniumtest {

    public static void main(String[] args) {
        System.setProperty("webdriver.ie.driver","D:/Softwares/IEDriverServer_Win32_2.39.0/IEDriverServer.exe");
        WebDriver driver = new InternetExplorerDriver();
        //System.setProperty("webdriver.chrome.driver","D:/Softwares/chromedriver_win_17.0.963.0/chromedriver.exe");
        //WebDriver driver = new ChromeDriver();

        //WebDriver driver = new RemoteWebDriver(DesiredCapabilities.chrome());
        //driver.get("http://www.google.com");

        driver.get("http://google.com");

    }

}

获得以下错误:

Exception in thread "main" org.openqa.selenium.remote.SessionNotFoundException: Unexpected error launching Internet Explorer. IELaunchURL() returned 80070005 for URL 'http://localhost:26504/' (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.32 seconds
Build info: version: '2.39.0', revision: 'ff23eac', time: '2013-12-16 16:12:12'
System info: host: 'ACE-PC', ip: '192.168.0.6', os.name: 'Windows Vista', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0_07'
Driver info: org.openqa.selenium.ie.InternetExplorerDriver
    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:193)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:151)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:554)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:201)
    at org.openqa.selenium.ie.InternetExplorerDriver.run(InternetExplorerDriver.java:194)
    at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:184)
    at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:155)
    at seleniumtest.main(seleniumtest.java:13)

我刚刚按照以下步骤操作,但它没有帮助我:

  

需要在所有区域中设置相同的安全级别。要做到这一点   以下步骤:

Open IE
Go to Tools -> Internet Options -> Security
Set all zones to the same protected mode, enabled or disabled should not matter.

2 个答案:

答案 0 :(得分:0)

  • 有时管理员已阻止IE更改所需的保护模式设置。

    • 相反,您可以使用Selenium的Desired capabilities功能来启动具有设置功能的IE。
    • 这样您就不会依赖管理员来更改设置
    • 可以使用以下代码。

      DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();

      capabilities.setCapability(CapabilityType.BROWSER_NAME,“IE”);

      capabilities.setCapability(InternetExplorerDriver。   INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,TRUE);

      String driverPath =“C:\ Selenium \”;

      System.setProperty(“webdriver.ie.driver”,driverPath +“IEDriverServer.exe”); WebDriver驱动程序=新的InternetExplorerDriver(功能); driver.manage()窗口()最大化();

答案 1 :(得分:0)

它有效!!! 我按照以下步骤操作:

  • 打开IE
  • 转到工具-> Internet选项->安全
  • 将所有区域设置为相同的保护模式

启用或禁用无关紧要。