【发布时间】:2017-02-02 09:50:18
【问题描述】:
在中间运行我的所有脚本时获取NullPointerException。我在属性文件中写入了xpath,我正在将属性文件加载到BeforeSuite 中。元素将出现,页面也将出现。在定位器中获取null。
【问题讨论】:
-
现在,是时候阅读提问指南了。 catb.org/~esr/faqs/smart-questions.html
在中间运行我的所有脚本时获取NullPointerException。我在属性文件中写入了xpath,我正在将属性文件加载到BeforeSuite 中。元素将出现,页面也将出现。在定位器中获取null。
【问题讨论】:
可能是您的属性文件没有给出您元素的确切值。 尝试通过提供属性名称来调用此函数。
public static String getProperty(String propertyname)
{
Properties prop = new Properties();
InputStream input = null;
try {
input = new FileInputStream(("path of your property file"));
// load a properties file
prop.load(input);
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
System.out.println(prop.getProperty(propertyname));
//Return the property value
return prop.getProperty(propertyname);
}
【讨论】: