当前位置: 首页 > 知识库问答 >
问题:

在执行selenium脚本时获取“java.lang.NullPointerException”

公冶浩慨
2023-03-14

好心的,谁能帮助关于以下例外的根本原因。

test_automation.tc_invoice_printing.tc_input_fields_validation(tc_invoice_printing.java:37)在java.base/jdk.internal.reflect.nativeMethodAccessorImpl.Invoke0(本机方法)在java.base/jdk.internal.reflect.nativeMethodAccessorImpl.Invoke(未知源)在java.base/jdk.internal.reflect.nativeMethodAccessorImpl.Invoke(未知源)在.suiterunner.runtest(suiterunner.java:455)在org.testng.suiterunner.runsequency(suiterunner.java:450)在org.testng.suiterunner.privaterun(suiterunner.java:415)在org.testng.suiterunner.java:364)在org.testng.suiterunner.runsuite(suiterunner.java:52)在org.testng.suiterunner.runsuite(

脚本:

@Test
public void TC_input_fields_validation() {

        int default_input_fields_count = Invoke_Test_Instance.driver.findElements(By.xpath("//input[contains(@class,'input-lg form-control')]")).size();
        System.out.println("default field count" + default_input_fields_count);
        System.out.println(Invoke_Test_Instance.driver.findElement(By.xpath("/html/body/div[1]/div/div[2]/div[2]/div/div[2]/div/form/div/div/div[2]/div/div/a")).isDisplayed());
        Invoke_Test_Instance.driver.findElement(By.xpath("/html/body/div[1]/div/div[2]/div[2]/div/div[2]/div/form/div/div/div[2]/div/div/a")).click();
        Invoke_Test_Instance.driver.findElement(By.xpath("/html/body/div[1]/div/div[2]/div[2]/div/div[2]/div/form/div/div/div[2]/div/div/a")).click();
        Invoke_Test_Instance.driver.findElement(By.xpath("/html/body/div[1]/div/div[2]/div[2]/div/div[2]/div/form/div/div/div[2]/div/div/a")).click();
}

共有1个答案

谭铭
2023-03-14

通过在@BeforeClass下定义的方法中插入与web驱动程序初始化相关的方法,我的问题得到了解决

 类似资料:
  • 请大家帮助了解以下异常的根本原因。 JAVAlang.NullPointerException在测试自动化中。TC_发票_打印。java上的TC_输入_字段_验证(TC_发票_打印.java:37)。base/jdk。内部的反映NativeMethodAccessorImpl。在java上调用0(本机方法)。base/jdk。内部的反映NativeMethodAccessorImpl。在java上

  • java.lang.NullPointerException(位于org.openqa.selenium.support.pageFactor.defaultelementLocator.java:69)(位于org.openqa.selenium.support.pageFactor.internal.locatingelementandler.invoke(locatingelementand

  • 我已经在我的系统中安装了python、pip和selenium,我正在基本站点上测试一个示例代码。 代码: 如何解决此问题?

  • 问题内容: 我的android应用程序功能的一部分是放置我在init.d中编写的脚本,这样它将在每次启动时执行。(显然,我的应用仅适用于root用户) 这是我在做什么: 我遇到麻烦的地方是“ update-rc.d脚本99”行,失败的原因是“找不到update-rc.d”错误。 有谁知道正确的命令是什么才能使它在Android中工作? 我意识到这并不是发布此问题的最合适地点,但是我已经意识到该社区

  • 它涵盖了哪些用例?何时应该使用而不是常规的? 这个问题与硒有关,但与语言无关。

  • 其中test.py为: 我为python、geckdodriver和firefox授予了整个lib目录的权限,以便在IIS_IUSRS(使用Windows)下进行完全控制。 Geckodriver的日志: 产生错误: 文件“C:\inetpub\wwwroot\jobdescription\test.py”,第13行,在driver=webdriver.firefox(firefox_option