maven 如何使用selenium和eclllpse验证多重屏幕?

iqih9akk  于 2023-02-03  发布在  Maven
关注(0)|答案(3)|浏览(73)

我是新的 selenium 。我正在验证两个屏幕,登录和密码屏幕使用 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();
}

}

w6mmgewl

w6mmgewl1#

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

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

eh57zj3b2#

您可以在通过(登录页面)后使用下一个页面验证您的进度和步骤,这样您就可以使用显式wait方法验证页面上的页面标题或元素

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

c0vxltue3#

您也可以使用element_to_be_selected来代替element_to_be_clicked

相关问题