处理警报并等待后,页面未加载并且无法找到元素 硒中

问题描述

处理警报并等待(运行时弹出窗口,)后,页面未加载,这就是找不到元素的原因。 (在Selenium中)没有得到这样的元素:无法找到元素

''''''公共类ApplicantLoginPageTest扩展了TestBase {

  @Test
    public void init() throws Exception { 
      
     
    ApplicantLoginPage applicantLoginPage = PageFactory.initElements(driver,ApplicantLoginPage.class);
    
      applicantLoginPage.getApp(prop.getProperty("urlapp"));
      Thread.sleep(3000);
      
      applicantLoginPage.login(prop.getProperty("un"));
      Thread.sleep(3000);
            
      applicantLoginPage.instruct1();
      Thread.sleep(3000);
      
      applicantLoginPage.TestClick();
      try {
            webdriverwait wait = new webdriverwait(driver,2);
            wait.until(ExpectedConditions.alertIsPresent());
            Alert alert = driver.switchTo().alert();
            alert.accept();
            driver.switchTo().defaultContent();
        } catch (Exception e) {
        }
         applicantLoginPage.TestCamera();
        Thread.sleep(15000);
        applicantLoginPage.PreviewRecord();
        Thread.sleep(15000);
        applicantLoginPage.instruct2();
        Thread.sleep(3000);
    }
}''''

解决方法

删除以下语句,然后重试:

driver.switchTo().defaultContent();