0

I am trying to use Selenium WebDriver to click the 'OK' button in a modal that appears after submitting a form on a page.

Driver.SwitchTo().Alert() fails, and so does switching the window handle. I have also tried Driver.SwitchTo().ActiveElement() but that also fails. The driver is still recognising elements on the page before the button that opens the modal was clicked, so I know it is definitely not switching over, which makes Xpath and CssSelector useless for the meantime.

I have tried switching browsers but that doesn't have an effect.

<div id="confirmModal" class="modal fade">
<div class="modal header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
<h3 id="myModalLabel">Confirmation</h3>
</div>
<div class="modal-body">
<p>Confirm?</p>
<div class="alert alert-block">
<p> Are you sure? You can not undo this </p>
</div>
</div>
<div class="modal-footer">
<input type="button" class="btw" data-dismiss="modal" value="Cancel" aria-hidden="true">
<input type="button" value="OK" id="confirmation-submit" class="btn btw-primary">
</div>

</div>

Any suggestions would be helpful - thank you!

2 Answers 2

1

I have solved a very similar problem to yours with the following code:

new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementIsVisible(okButton_id));
IWebElement okButton = driver.FindElement(By.Id(okButton_id));
okButton.Click();
Sign up to request clarification or add additional context in comments.

Comments

0

Clement's answer solved this for me. Except, I was using python, so what you need to do is invoke:

driver.implicitly_wait(1)

Or for more seconds if this doesn't work.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.