Selenium: 空指针error

Error 类型:空指针

可能原因一:

只是引用了该类,但是没有对该类进行实例化(即没有New 一下),即没有给该类分配内存,所以导致空指针;

类调用前注意要实例化,否则会导致空指针错误.

首先声明DashboardPage类型的引用,然后创建DashboardPage类型的对象,然后访问DashboardPage 类中的menuDashboardPage 属性

public static DashboardPage dashboard;

helper = new TestHelper();
dashboard = (DashboardPage) helper.getPage("DashboardPage");

driver.findElement(By.xpath(dashboard.menuOnDashboard.xpath)).click();

可能原因二:

该元素的xpath为空,需检查对应的CSV文件里该元素的xpath

原文地址:https://www.cnblogs.com/xriverside/p/4201648.html