使用Internet Explorer驱动程序运行selenium webdriver测试用例时出现空指针异常

时间:2014-06-01 18:11:33

标签: selenium

以下是我的代码:

package mypackage;
import java.io.File;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class myclass {
public static WebDriver driver;
public static File file;
public static void main (String[] args){

// declaration and instantiation of objects/variables
file = new File("C:\\DATA\\IEDriverServer_x64_2.42.0\\IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());  
driver = new InternetExplorerDriver();
String baseURL = "http://www.google.com";
String expectedTitle = "Google";        
String actualTitle = "";

// launch IE and direct it to the Base URL        
driver.get(baseURL);         

// get the actual value of the title        
actualTitle = driver.getTitle();        
/*         
* compare the actual title of the page witht the expected one and print         
* the result as "Passed" or "Failed"         
*/       
if (actualTitle.contentEquals(expectedTitle)){            
System.out.println("Test Passed!");        
} else {            
System.out.println("Test Failed");        
}    

//close Firefox        
driver.close();                

// exit the program explicitly        
System.exit(0);

}
}

当我运行时,我得到以下异常。

    Started InternetExplorerDriver server (64-bit)
2.42.0.0
Listening on port 42229
Exception in thread "main" java.lang.NullPointerException
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:600)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:241)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:226)
        at org.openqa.selenium.ie.InternetExplorerDriver.run(InternetExplorerDriver.java:182)
        at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:174)
        at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:146)
        at mypackage.myclass.main(myclass.java:15)

3 个答案:

答案 0 :(得分:0)

我也有这个问题。我尝试过32位和64位驱动程序。我正在使用IE11,并已按照Selenium文档配置IE11并更新了我的Windows注册表。 https://code.google.com/p/selenium/wiki/InternetExplorerDriver#Required_Configuration

答案 1 :(得分:0)

Selenium服务器今天刚刚更新到2.42.2来解决这个问题!

https://code.google.com/p/selenium/issues/detail?id=7415

http://docs.seleniumhq.org/download/

答案 2 :(得分:0)

实际上我遇到了与IEDriverServer_x64_3.5.1.exe相同的问题,但是旧问题(IEDriverServer_x64_2.53.0.exe)已经解决了。

我很沮丧,因为我无法使用新版本(&gt; 3.0)