Java Selenium程序在搜索框中登录Gmail帐户,检查是否存在 发短信,这工作正常。如何检查消息是成功还是失败如果我编写一个单独的类,即获取会话ID为null
WebElement searchbox = driver.findElement(By.xpath("//input[@placeholder='Search mail']"));
Thread.sleep(100);
searchbox.click();
searchbox.sendKeys("SAP to Magento stock sync");
Thread.sleep(100);
searchbox.sendKeys(Keys.ENTER);
Thread.sleep(1000);
new WebDriverWait(driver, 30).until(ExpectedConditions
.visibilityOfElementLocated(By.className("xY a4W")));
WebElement NumberofRecord = driver.findElement(By.className("xY a4W"));
System.out.println(NumberofRecord.getText());
错误:
TimeoutException: Expected condition failed: waiting for visibility of element located by By.className: xY a4W (tried for 30 second(s) with 500 milliseconds interval)
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:81)
答案 0 :(得分:0)
// extract notification subjects
ArrayList<WebElement> notificationsSubjects = ...// code to locate displayed subjects
// resolve subjects
for (WebElement element: notificationsSubjects) {
if (element.getText().split(": SAP")[0] == "SUCCESS") {
// do something
}
else if (element.getText().split(": SAP")[0] == "ERROR") {
// do something else
}
else {
System.out.print("Unexpected subject.");
}