【发布时间】:2020-03-29 14:24:59
【问题描述】:
我正在尝试在 SalesForce 网站上打印错误消息,原因是输入了错误的用户名和密码
package today;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Gmail {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver.exe"); WebDriver mail=new ChromeDriver();
mail.get("https://login.salesforce.com/?locale=in");
mail.findElement(By.cssSelector("#username")).sendKeys("judinkp@gmail.com");
mail.findElement(By.xpath("//*[@id=\"password\"]")).sendKeys("23232");
mail.findElement(By.id("Login")).click();
System.out.println(mail.findElement(By.xpath("//*[@id='error']")).getText());
}
}
我的脚本一直运行到它点击Login,但网站中打印的错误消息没有打印在我的控制台中,我收到以下错误消息
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@class='loginError']"}
(Session info: chrome=80.0.3987.149)
Xpath 是浏览器给定的 Xpath。
网站链接:https://login.salesforce.com/?locale=in
【问题讨论】: