How to close this dialog

  • This is the code for an opening specific page and after that popup appear which I am unable to handle.

    I have used alert, switchTo, etc..

    //Open Browser
      WebDriver driver = new ChromeDriver();
    //Enter the URL
      //I Agree PopUp
      driver.findElement(By.xpath("//button[contains(text(),'I Agree')]")).click();
      //after this, that popup appears and then its get stop.... u can find it in the image below

    Suggest some way to close it.

    enter image description here

  • It is not a JavaScript alert, nor a new Window. It is just two HTML DIV elements that mimic a styled alert dialog. One containing a blur for the whole page and the other with the content of the dialog. JavaScript Alerts look different and are not part of the page, therefore you can also not find them in the page source. Look here for a real JS-Alert example, click try.

    I tried to close the dialog on that page with a CSS Selector named .dialogClose, it works. You can use unique classes (class="uniqueclassname anotherclassname") to find elements.

    In your case, the following code should work:


    Some issue I ran into when testing this on my machine:

    • The dialog is not always shown, seems random. Possibly add a try/catch and ignore the dialog if it was not found.
    • The agree button is slow to show. You might need to research waits.

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2