2017-02-13 103 views
0

1.为什么不能关闭警报弹出窗口?为什么不能关闭警报弹出窗口?

  • 我都试过警报等,它将关闭弹出,但然后我得到了奇怪的测试,其中弹出dosnt关闭/
  • 3.我的代码:

    public void closeAlertPopupBox() throws AWTException, InterruptedException { 
        try { 
         Alert alert = this.wait.until(ExpectedConditions.alertIsPresent()); 
          alert.accept(); 
          System.out.println("The popup has been successfully closed"); 
        } catch (UnhandledAlertException f) { 
         Alert alert = this.driver.switchTo().alert(); 
         alert.accept(); 
        } catch (Exception e) { 
         System.out.println("Unable to close the popup"); 
         Assert.assertFalse(true, "Unable to close the popup, Exception: " + e.getMessage()); 
        } 
    } 
    
  • 上述代码的工作,但我得到其中惯于紧密而且会有测试失败奇数弹出。

  • 使用以下所需的功能工作,但然后我在TestNG上得到一个错误,它说有一个'意外的弹出',但代码仍然是acepts并关闭弹出窗口。

  • 我的代码:

       System.setProperty("webdriver.chrome.driver", Constant.CHROME_DRIVER_DIRECTORY); 
    
          DesiredCapabilities caps = DesiredCapabilities.chrome(); 
          LoggingPreferences logPrefs = new LoggingPreferences(); 
          logPrefs.enable(LogType.BROWSER, Level.ALL); 
          UnexpectedAlertBehaviour.ACCEPT); 
          caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs); 
          webdriver = new ChromeDriver(caps); 
    
  • 任何想法找到解决这个问题的工作? enter image description here 感谢您帮助

    +0

    为3号执行一些奇怪的原因会导致测试失败 – Gbru

    +0

    警报警报= driver.switchTo()警报()。 alert.accept();或alert.dismiss(); –

    回答

    1

    当你只接受popup.To结束,我们必须使用关闭提醒的方法弹出 请遵循详细

    Alert alert= driver.switchTo().alert(); 
    alert.dismiss(); 
    

    下面的代码,如果问题然后保持你可以尝试处理相同即

    Alert alert= driver.switchTo().alert(); 
    Thread.sleep(500) 
    alert.dismiss();