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

执行selenium脚本时获取java.lang.NullPointerExcema

羊毅庵
2023-03-14

请大家帮助了解以下异常的根本原因。

JAVAlang.NullPointerException在测试自动化中。TC_发票_打印。java上的TC_输入_字段_验证(TC_发票_打印.java:37)。base/jdk。内部的反映NativeMethodAccessorImpl。在java上调用0(本机方法)。base/jdk。内部的反映NativeMethodAccessorImpl。在java上调用(未知源)。base/jdk。内部的反映DelegatingMethodAccessorImpl。在java上调用(未知源)。base/java。朗。反思。方法在组织中调用(未知源)。testng。内部的方法调用助手。org上的invokeMethod(MethodInvocationHelper.java:124)。testng。内部的调用者。org上的invokeMethod(Invoker.java:580)。testng。内部的调用者。org上的invokeTestMethod(Invoker.java:716)。testng。内部的调用者。invokeTestMethods(Invoker.java:988)位于org。testng。内部的TestMethodWorker。org上的invokeTestMethods(TestMethodWorker.java:125)。testng。内部的TestMethodWorker。在org上运行(TestMethodWorker.java:109)。testng。测试者。privateRun(TestRunner.java:648)位于org。testng。测试者。在org上运行(TestRunner.java:505)。testng。SuiteRunner。在org上运行测试(SuiteRunner.java:455)。testng。SuiteRunner。在org上按顺序运行(SuiteRunner.java:450)。testng。SuiteRunner。privateRun(SuiteRunner.java:415)位于org。testng。SuiteRunner。在org上运行(SuiteRunner.java:364)。testng。SuiteRunnerWorker。运行套件(SuiteRunnerWorker.java:52)位于org。testng。SuiteRunnerWorker。在org上运行(SuiteRunnerWorker.java:84)。testng。TestNG。在org上依次运行suitessequential(TestNG.java:1208)。testng。TestNG。在org上本地运行suitesLocal(TestNG.java:1137)。testng。TestNG。org上的runSuites(TestNG.java:1049)。testng。TestNG。在org上运行(TestNG.java:1017)。testng。遥远的抽象远程测试。在org上运行(AbstractRemoteTestNG.java:114)。testng。遥远的远程测试。initAndRun(RemoteTestNG.java:251)位于org。testng。遥远的远程测试。main(RemoteTestNG.java:77)

脚本

@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驱动程序初始化相关的方法来解决

 类似资料:
  • 好心的,谁能帮助关于以下例外的根本原因。 test_automation.tc_invoice_printing.tc_input_fields_validation(tc_invoice_printing.java:37)在java.base/jdk.internal.reflect.nativeMethodAccessorImpl.Invoke0(本机方法)在java.base/jdk.int

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

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

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

  • 问题内容: 我正在使用AJAX返回包含脚本的响应。 通过该脚本,如何确定脚本在其中运行的父元素的ID,而不将ID传递给服务器?有办法吗? 谢谢。 问题答案: 如果您为脚本分配了ID(在古老的浏览器中会爆炸),则可以尝试:

  • error-driver=webdriver.firefox()文件“/users/grey/.pyenv/versions/3.7.3/lib/python3.7/site-packages/selenium/webdriver/firefox/webdriver/firefox/webdriver.py”,第164行,在init self.service.start()文件“/users/gr