【发布时间】:2017-10-12 14:53:15
【问题描述】:
我在 com.sun.jdi.InvocationException 发生调用方法时收到“空指针异常”。在 selenium 中使用 PageFactory 时。
我正在尝试使用 Junit 创建一个测试用例。当我尝试调用父类中存在的方法时,我面临空指针异常
我的代码如下
class 1:
public class Browser {
public static RemoteWebDriver driver;
public void openInternetExplorer(){
System.setProperty("webdriver.ie.driver","path to ie driver");
driver = new InterExplorerDriver();
driver.get("https://www.gmail.com")
}
}
Class2:
public class Elements extends Browser{
public enterText(WebElement element, String text){
element.sendKeys(text);
}
}
Class3:
public BaseClass extends Elements{
BaseClass(){
PageFactory.initElements(driver,this);
}
}
Class4:
public Testing extends BaseClass{
@FindBy(id="unique_name") WebElement uniqName;
public void method1(){
openInternetExplorer();
enterText(uniqName,"SuperMan");
}
}
Error Which i am getting is
java.lang.NullPointerException
at org.openqa.selenium.support.pagefactory.DefaultElementLocator.findElement(Defaul tElementLocator.java:69)
at org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler.invoke(L ocatingElementHandler.java:38)
at com.sun.proxy.$Proxy7.click(Unknown Source)
at com.framework.Browser.clickAction(Element.java:5)
at com.framework.Testing.Testing(Testing.java:7)
如果我在这里遗漏了什么,请告诉我。
【问题讨论】:
标签: java eclipse selenium-webdriver junit nullpointerexception