0

So there are multiple calendars (datepickers) on the page and I have managed to click on the desired calendar. enter image description here

I want to click on the active date (current date). class="day active" How can I find this element after clicking on desired calendar glyphicon?

P.S. when I copy selector for this- I am getting

body > div:nth-child(27) > div.datepicker-days > table > tbody > tr:nth-child(4) > td.day.active

And when I inspect element and search td.day.active, I am able to reach that element. enter image description here

So I have used below syntax for clicking on it.

WebDriverWait(driver, 30).until(lambda driver: driver.find_element_by_css_selector('td.day.active')).click()

But getting ElementNotVisibleException

I want a generic script to do this. I want to select the active date on this calendar. clicking on xpath doesnt work as there is no absolute path to it.

1 Answers1

0

There can be a possibility where a single html page has more than one datepickers If we want to click on active date of specific datepicker then selector can be used

.dropdown-menu:nth-child(9) > .datepicker-days .active

where "9" is the occurence of that datepicker. i.e. there are 9 or more datepicker elements on the page.

So for above question, child is 27 hence below code will click on active date (current date) of datepicker.

WebDriverWait(driver, 30).until(lambda driver: driver.find_element_by_css_selector(".dropdown-menu:nth-child(27) > .datepicker-days .active")).click()

P.S. Even if you manage to click on calendar xpath, clicking on active date will require nth-child value of calendar.