我正在我的本地系统上测试它,并尝试验证用户是否已成功登录并登陆正确的页面。 尝试将字符串数据与webelement数据进行比较时出错。
getActiveNetworkInfo
答案 0 :(得分:2)
不使用Webelement
,而是String
方法使用getText()
,因此它会为您提供实际的字符串。不是Webelement。
注意:使用absolute
xpath而不是使用relative
xpath。有关xpath
教程的详细信息,请参阅此link。
String expectedtext="Summary";
String actualtext = driver.findElement(By.xpath("//div/h3[text()='Summary']")).getText();
System.out.println(actualtext);
if (expectedtext.equalsIgnoreCase(actualtext))
{
System.out.println("User succesfully loggedIN");
}
else
{
System.out.println("Invalid credtendials!!");
}
答案 1 :(得分:0)
试试这个 - String expectedtext ="摘要&#34 ;; String actualtext = null;
actualtext = driver.findElement(By.xpath("/html/body/div[3]/div/ng-include/div/div/div[1]/div/h3")).gettext();