Not able to access bootstrap modal dialog in Selenium Webdriver Not able to access bootstrap modal dialog in Selenium Webdriver selenium selenium

Not able to access bootstrap modal dialog in Selenium Webdriver


I found the solution for this after so much googling... here is the simple solution for this

//Switch to active element here in our case its model dialogue box.driver.switchTo().activeElement();Thread.sleep(3000);// find the button which contains text "Yes" as we have dynamic iddriver.findElement(By.xpath("//button[contains(text(),'Yes')]")).click();

This code solves my problem.


Instead ID try using xpathlike:

By.XPath("//div[@class='bootstrap-dialog-footer-buttons']//button[text()='Yes']")

I hope that helps.


In cases where ID of the element is not predefined, CSS class can be used as valid selector.That, of course, applies if there is only one element with that class in the page.For multiple elements i would suggest that you mark each one of them with different css class, like:

<button class="yes btn btn-default" id="868d2d8a-67f6-4308-a3c8-0246a5d4618c">Yes</button><button class="no btn btn-default" id="23e4d027-ef32-4b58-b8b6-6f95bead2db4">No</button>

and then you can use simple CSS selector like

button.btn-default.yes

to reach the desired element using selenium.