How to close the popup modal dialog box using selenium (Java) tool for the below screenshot?
-
Is this pop up a part of DOM or it's a separate window?– Alexey R.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 ManeOct 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 VOct 4, 2018 at 3:34
-
Is it Windows Popup or Bootstrap Popup?– SachinthaOct 4, 2018 at 6:22
-
It is Bootstrap Popup– Anand VOct 4, 2018 at 8:50
1 Answer
I think there are two things you could try here
Alert alert = driver.switchTo().alert();
alert().dismiss();
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()) {
element.click();
}
-
1The issue is solved. It is not an alert. Your second suggestion is the solution for that. Thanks Jack– Anand VOct 5, 2018 at 6:43