如何解决在排除以下代码时获取错误=线程“main”中的异常java.lang.NullPointerException?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (133)

/ * 1538254052650 Marionette DEBUG [6442450945]收到了针对http://www.demo.guru99.com/v4/index.php的 DOM事件页面显示 线程“main”中的异常java.lang.NullPointerException * /

public static void setUp()throws Exception {

System.setProperty("webdriver.gecko.driver","D:\\\\Selenium\\\\New\\\\Driver('s)\\\\geckodriver.exe");

File pathBinary = new File("C:\\Program Files\\Mozilla Firefox\\firefox.exe");

FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);  

DesiredCapabilities desired = DesiredCapabilities.firefox();

FirefoxOptions options = new FirefoxOptions();

desired.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options.setBinary(firefoxBinary));

WebDriver driver = new FirefoxDriver(options);

driver.navigate().to("http://www.demo.guru99.com/v4/index.php");

driver.manage().window().maximize();

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

}

public static void main(String args[]) throws Exception {

    setUp();

    driver.findElement(By.name("uid")).sendKeys("mngr152686");

    driver.findElement(By.name("password")).sendKeys("YgabAzy");

    driver.findElement(By.name("btnLogin")).click();

    Thread.sleep(3000);

   System.out.println("Login Succsful");


}
提问于
用户回答回答于

尝试通过XPath传递值。有时,当网页中缺少特定元素时,可以帮助解决空指针异常。

扫码关注云+社区

领取腾讯云代金券