How to Validate Multiple screen using selenium with eclilpse?

Viewed 58

I am new to selenium. I am validating two screens, Login and Password screens using selenium. The First screen is Login. If the username is correct then it will move to next screen that is Password. But in the Password screen the driver not putting the password into the input box, nothing is happening. It stops at Password screen. Any solution for that ? my code is below. It is working for Login screen.

  package Second;

  import org.openqa.selenium.By;
  import org.openqa.selenium.WebDriver;
  import org.openqa.selenium.chrome.ChromeDriver;

  public class Second {

public static void main(String[] args) {
    System.setProperty("webdriver.chrome.driver", "E:\\Installed 
   Application\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
     driver.get("https://gamaa.ui.in/");
        driver.findElement(By.id("username")).sendKeys("test");
        driver.findElement(By.className("mat-primary")).click();
       
        driver.findElement(By.id("password")).sendKeys("1234");
        driver.findElement(By.className("mat-primary")).click();
}

}

2 Answers

It is taking time to load the next page element use WebDriverWait() and wait for elementToBeClickable()

 new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.id("password"))).sendKeys("jaipur");

You can validate your progress and steps using the next page after passing (login page) so you can validate with the page title or element on the page with explicitly wait method

String actualTitle =driver.getTitle();
String expectedTitle="Next Page Title";
if(actualTitle.equalsIgnoreCase(expectedTitle))
System.out.println("Title Matched");
else
System.out.println("Title didn't match");

Or

Assert.assertEquals("Condition true", actualTitle, expectedTitle);

Related