尝试在Selenium中实现页面对象模型时获取空指针异常

时间:2018-09-29 02:37:12

标签: selenium webdriver

我有2个Java类:

  • Test.java
  • CreateCandidates.java

    CreateCandidates.java

    AssignmentExpression

Test.java

public class CreateCandidates {


WebDriver driver;

public CreateCandidates(WebDriver driver){
    this.driver = driver;
}

WebElement firstname = driver.findElement(By.id("first_name"));
WebElement lastname = driver.findElement(By.id("last_name"));
public void fillDetails() {
firstname.sendKeys("firstname");
lastname.sendKeys("lastname");
}

我收到NullPointerException。

public class Test{

CreateCandidates candidates = new CreateCandidates(driver);
candidates.fillDetails();

0 个答案:

没有答案