如何使用selenium修复此java.lang.nullpointerException

时间:2017-04-20 14:28:21

标签: java selenium-webdriver

我正在异常

   Exception in thread "main" java.lang.NullPointerException
   at com.wd.programs.Gmail_Login.email(Gmail_Login.java:17)
   at com.wd.programs.Gmail_Login.main(Gmail_Login.java:29)
运行以下代码时

 public class Gmail_Login extends HandlingDropdowns  {
    WebDriver driver ;

    public Gmail_Login (WebDriver d) {
      super(d);
    }

    public void email(String e) {

      driver.findElement(By.cssSelector("input[type='email']")).sendKeys(e);
    } 


    public static void main(String[] args) {
      WebDriver driver = new FirefoxDriver();
      Gmail_Login gl = new Gmail_Login(driver);
      gl.openApplication("http://www.gmail.com");
      gl.email("rize.test1");

    }

 }

1 个答案:

答案 0 :(得分:0)

您没有分配传递给import functools import operator return functools.reduce(operator.and_, [df[name] == kwargs.get(name, '') for name in notall]) WebDriver实例的Gmail_Login实例。因此,WebDriver类中的driver变量的值为Gmail_Login。当您尝试使用值为null的此变量调用任何方法时,它将抛出null。这样做,它将解决异常:

NullPointerException