Judinカイザー:
私は間違ったユーザー名とパスワードを入力するための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("[email protected]");
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
Dipak Bachhav:
あなたは、ソリューションの下にしてみてくださいすることができます:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class LoginScreen {
public static void main(String[] args) {
System.out.println("launching chrome browser");
System.setProperty("webdriver.chrome.driver", "C:\\selenium\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.navigate().to("https://login.salesforce.com/?locale=in");
driver.get("https://login.salesforce.com/?locale=in");
driver.findElement(By.cssSelector("#username")).sendKeys("[email protected]");
driver.findElement(By.id("password")).sendKeys("23232");
driver.findElement(By.id("Login")).click();
WebDriverWait wait = new WebDriverWait(driver,20);
WebElement error= wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("error")));
System.out.println(error.getText());
}
}