Bharat Mane Bharat Mane - 14 days ago 7
Java Question

How to handle modal dialog box in Selenium WebDriver with Java?

There is a scenario where I get the modal dialog box when I tried to login with Twitter.


Launch Url www.twitter.com -> click on Login button -> it opens modal dialog box.


I am not able to handle this scenario because "webdriver" is not getting access to the dialog box. Is there any way to handle this?

Answer

just write the following code after click on login button:

Thread.sleep(3000); //i use here wait implicit wait. Try to use explicit wait here.

driver.findElement(By.cssSelector("a.Icon.Icon--close.Icon--medium.dismiss")).click();