Reputation: 49
I am actually new to selenium web driver and stackoverflow. I am working on automating test cases for a 'forgot password' feature which has a dialog box when unregistered email address is entered.
I want to validate the message 'This email is not registered!' in the dialog box ,but not sure how to proceed as i am using xPath which keeps changing for the message 'This email is not registered'.
This email account is not registered!
@Test
public void checkForgotPasswordWithInvalidCredentials() throws Exception {
driver.findElement(By.xpath(".//*[@id='forgetBtn']")).click();
driver.findElement(By.xpath(".//*[@id='emailInput']")).sendKeys("[email protected]");
driver.findElement(By.xpath(".//*[@id='verify_btn']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath(".//*[@id='alert_box_14']/p")).isDisplayed();
}
In the above code, the Xpath for the alert message(.//*[@id='alert_box_14']/p) keeps changing.
Any help would be appreciated. Thanks!
Upvotes: 1
Views: 747
Reputation: 50949
If the number keep changing you can use partial id
driver.findElement(By.xpath(".//*[contains(@id, 'alert_box')]/p")).isDisplayed();
Upvotes: 2