I am running into an issue where I am unable to select a button in the modal. The modal only appears when running my selenium script and does not appear when manually traversing the webpage. Interestingly enough the modal does consistently appear when my script runs try/except as shown below, but the program advances to the next step and is not able to get the element to click. Trying to get the element after this try:except also fails. The modal does not show up otherwise.
try:
element=driver.find_element_by_xpath('//div[contains(@href,"appointment")]')
element.click()
print("Looking for the modal button")
except NoSuchElementException:
print("*****Did not find the modal button")
I have tried the following with no success:
WebDriverWait(driver, 300).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn btn-default btn-ok'][@data-dismiss='modal']"))).click()
This simply times out.Different methods to get the element:
element = driver.find_element_by_class_name("btn.btn-default.bt-ok")
and
element=driver.find_element_by_xpath('//div[contains(@href,"appointment")]')
In both cases the element is not found.
- Tried running with cookies, and the result is the same.
- Tried various sleep timers, but the modal does not appear during this sleep period
Here is the HTML Snippet of this section. Not sure if <div class =schedule-modal is a hint that there is some logic behind how/when the modal shows up?
<div class="schedule-modal modal fade in" tabindex="-1" role="dialog" aria-hidden="false" style="display: block;">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<p><strong> Text
</p>
</div>
<div class="modal-footer">
<a class="btn btn-default btn-ok" href="/appointment">Start Appointment</a>
</div>
</div>
</div>
</div>
Thanks in advance for your help!
Update
Looks like the above code exists HTML code exists on the source page before the modal pops up which is why I was not able to access the element. My next question is what is this schedule-modal function doing:
function showNotice(dom) {
var $scheduleModal = $(".schedule-modal");
if ($scheduleModal.length) {
var link = $(dom).attr('href');
$scheduleModal.find('.btn-ok').attr('href', link);
$scheduleModal.modal('toggle');
return false;
}