[英]How to Check Success and Failure message from login form by using selenium?
以下代碼用於 g-mail 登錄。
package gmail_Login; import java.util.concurrent.TimeUnit; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class Login { //public static void main(String[] args) { // TODO Auto-generated method stub // created reference variable for WebDriver WebDriver drv; @Before public void setup() throws InterruptedException { // initializing drv variable using FirefoxDriver drv=new FirefoxDriver(); // launching gmail.com on the browser drv.get("https://gmail.com"); // maximized the browser window drv.manage().window().maximize(); drv.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); } @Test public void test() throws InterruptedException { // saving the GUI element reference into a "username" variable of WebElement type WebElement username = drv.findElement(By.id("Email")); // entering username username.sendKeys("fake mail id"); // clicking next button drv.findElement(By.id("next")).click();
}
我必須給出假 ID 然后單擊下一步按鈕錯誤消息即將到來,但如何檢查錯誤消息。
單擊下一步按鈕后,使用以下步驟獲取錯誤消息文本:
查找錯誤消息元素
WebElement msg=driver.findElement(By.id("errormsg_0_Email"));
獲取 msg 文本
字符串文本=msg.getText();
使用預期文本斷言/驗證文本
Assert.assertEquals(text,expectedText);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.