How to select time in dropdown of datepicker (Selenium & Python)

Viewed 4687

I want the script to select a specific time on the start time drop down.

I am using Selenium Chromedriver with Python for https://www.sailbox.ch/de/bootliste . I managed to open the drop down of the start time picker (hour:minutes). I tried several ways to place the click on the value 22:00.

This is the setup

from selenium.webdriver.support.ui import Select
driver = webdriver.Chrome()
driver.get("https://www.sailbox.ch/de/bootliste")
assert "sailbox" in driver.title

This opens the drop down of the start time date picker

driver.find_element_by_id("filterFormInput_timeFrom").click()
driver.implicitly_wait(4)

Then I tried multiple options:

Option 1

start_time = driver.find_element_by_xpath("//div[@class='xdsoft_time']//div[@data- 
hour='22'][@data-minute='00']")
driver.implicitly_wait(4)
start_time.click()

Option 2

driver.find_element_by_css_selector("div[@class='xdsoft_time' and text()='20:00']")

Option 3

driver.findElements(By.cssSelector("div[@data-hour='22'] and [@data-minute='00']")).click();

Currently, I get the error that 'the element is not clickable'. the goal is to select the value "22:00" from the drop down.

2 Answers

Actually it turns out that this website runs jQuery. Knowing that you can simply do:

driver.execute_script('$("#timeFrom").val("22:00").change();');

which would change your input to the desired time

You can use the below xpath to select the time, it works for both from and to times.

//div[starts-with(@class,'xdsoft_datetimepicker')][starts-with(@style,'display: block')]//div[.='22:00']

Screenshot: enter image description here

Related