【发布时间】:2015-09-03 12:00:38
【问题描述】:
当我尝试使用 @FindBy 注释在网页上查找元素时,出现 java.lang.NullPointerException。
我的代码 -
public class pageObject{
WebDriver driver;
@FindBy(id = "email")
WebElement searchBox;
@FindBy(id = "u_0_v")
WebElement submit;
void pageObject(String web){
FirefoxProfile profile = new FirefoxProfile();
profile.setAssumeUntrustedCertificateIssuer(false);
profile.setAcceptUntrustedCertificates(false);
this.driver = new FirefoxDriver(profile);
this.driver.get(web);
this.driver.manage().window().maximize();
this.driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
searchBox.click();
searchBox.sendKeys("er");
submit.click();
}
public static void main(String[] args){
new pageObject("https://www.facebook.com/?_rdr=p");
}
}
上面的代码有一个异常-
例外-
Exception in thread "main" java.lang.NullPointerException
at com.Selenium_Practice.pageObject.<init>(pageObject.java:29)
at com.Selenium_Practice.pageObject.main(pageObject.java:35)
我也试过用
@FindBy(how = HOW.ID , using = "email") and @FindBy(how = HOW.ID , using = "u_0_v")
但又得到了同样的空指针异常
【问题讨论】:
标签: java selenium nullpointerexception testng pageobjects