unable to select a date from date picker
this is the website working on https://www.phptravels.net/
when i used developer options and Ctrl F on firebug //div[@style='display: block; top: 390px; left: 680px;']//text()[contains(.,'15')]
i am able to find the date on the page
but when i am trying from the code i am unable to select the element
This is my code
self.driver.find_element(By.XPATH, "//div[@style='display: block; top: 390px; left: 680px;']//text()[contains(.,'" start_date "')]").click()
test_Flight.py:37:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\pages\search_flights_form.py:68: in set_start_date_pick
self.driver.find_element(By.XPATH, "//div[@style='display: block; top: 390px; left: 680px;']//text()[contains(.,'15')]").click()
..\..\..\..\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py:976: in find_element
return self.execute(Command.FIND_ELEMENT, {
..\..\..\..\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py:321: in execute
self.error_handler.check_response(response)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x052D6D18>
response = {'status': 404, 'value': '{"value":{"error":"no such element","message":"Unable to locate element: //div[@style=\'disp...ntent/shared/webdriver/Errors.jsm:395:5\\nelement.find/</<@chrome://remote/content/marionette/element.js:300:16\\n"}}'}
CodePudding user response:
Try like below and confirm.
driver.get("https://www.phptravels.net/")
wait = WebDriverWait(driver,30)
checkin = wait.until(EC.element_to_be_clickable((By.ID,"checkin")))
checkin.click()
date = 15
select_date = wait.until(EC.element_to_be_clickable((By.XPATH,f"//div[@class='datepicker-days']//td[text()='{date}']")))
select_date.click()
Update: As per comments to select date from Flights section.
driver.get("https://www.phptravels.net/")
wait = WebDriverWait(driver,30)
flights = wait.until(EC.element_to_be_clickable((By.XPATH,"//button[@aria-controls='flights']")))
flights.click()
departure_date = wait.until(EC.element_to_be_clickable((By.XPATH,"//input[contains(@class,'depart')]")))
departure_date.click()
date = 15
select_date = wait.until(EC.element_to_be_clickable((By.XPATH,f"(//div[@class='datepicker-days'])[3]/table/tbody/tr[3]/td[text()='{date}']")))
select_date.click()