How to close the popup modal dialog box using selenium (Java) tool for the below screenshot? Kindly Refer ans suggest

  • Is this pop up a part of DOM or it's a separate window?
    – Alexey R.
    Commented Oct 3, 2018 at 12:24
  • Just locate (take an XPath for) the Close button and click on it. Can you provide us the HTML code for Close button.
    – Bharat Mane
    Commented Oct 3, 2018 at 12:28
  • It is a part of DOM and HTML code for the close button is <button class="action-close" type="button" data-role="action"><span>X</span></button>. I have tried to close the popup using x-path. But it's not working
    – Anand V
    Commented Oct 4, 2018 at 3:34
  • Is it Windows Popup or Bootstrap Popup?
    – Sachintha
    Commented Oct 4, 2018 at 6:22
  • It is Bootstrap Popup
    – Anand V
    Commented Oct 4, 2018 at 8:50

1 Answer 1


I think there are two things you could try here

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

My other theory is that if you have tried to dismiss it manually through finding an ID for the X in the corner and trying to click it, you may have to wait until the element is clickable.

WebElement element = driver.findElement(By.xpath);
if (element.isDisplayed() && element.isEnabled()) {
  • 1
    The issue is solved. It is not an alert. Your second suggestion is the solution for that. Thanks Jack
    – Anand V
    Commented Oct 5, 2018 at 6:43

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.