如何使用 selenium 和 eclipse 验证多个屏幕?

How to Validate Multiple screen using selenium with eclilpse?

我是硒的新手。我正在使用 selenium 验证两个屏幕,登录和密码屏幕。 第一个屏幕是登录。如果用户名正确,那么它将移至下一个屏幕,即密码。 但是在密码屏幕中,驱动程序没有将密码输入输入框,没有任何反应。它停在密码屏幕。有什么解决办法吗?我的代码在下面。 它适用于登录屏幕。

  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();
}

}

加载下一个页面元素需要时间使用 WebDriverWait() 并等待 elementToBeClickable()

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

您可以在通过后使用下一页(登录页面)验证您的进度和步骤,因此您可以使用页面标题或页面上的元素进行显式等待方法验证

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");

或者

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