0

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
  driver.get("https://www.mariatash.com/");

  //I Agree PopUp
  driver.findElement(By.xpath("//button[contains(text(),'I Agree')]")).click();

  driver.findElement(By.xpath("//a[.='Appointments']")).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

2

1 Answer 1

1

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:

driver.findElement(By.cssSelector(".dialogClose").click();

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.
5
  • Yes. Some time it come and sometime it disappear. Cos firsttime i ran its worked but second time error came.
    – Sufiyaan
    Apr 18, 2019 at 10:48
  • Thanx but can u code for try n catch for same.
    – Sufiyaan
    Apr 18, 2019 at 10:50
  • @user38159 If this answer solves the problem of this question please accept the answers. For the try/catch, I suggest you first try yourself, read some documentation (w3schools.com/java/java_try_catch.asp), experiment and if you are stuck ask a new question instead. Apr 18, 2019 at 11:26
  • Thanx for your reply. As previous answer worked for firsttime and then its stopped..
    – Sufiyaan
    Apr 18, 2019 at 11:34
  • You do understand why it worked the first time and not the second time, not? Apr 18, 2019 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.