[英]Select date from date picker in yatra.Com
Hi I am new to python and Selenium. 嗨,我是python和Selenium的新手。 I am learning it out of interest. 我是出于兴趣而学习它。 My question is I want to select departure date and arrival date in below site. 我的问题是我想在下面的网站中选择出发日期和到达日期。 https://www.yatra.com/ I need the code in python using selenium, can any one please help me with this. https://www.yatra.com/我需要使用selenium的python中的代码,任何人都可以帮助我。 You can use any other library if required. 如果需要,您可以使用任何其他库。
Thanks for assistance. 感谢您的协助。
Example code: 示例代码:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
import random
driver = webdriver.Chrome("c:\\path\\to\\chromedriver.exe")
driver.maximize_window()
driver.get('https://www.yatra.com')
wait = WebDriverWait(driver, 10)
departure = wait.until(
expected_conditions.presence_of_element_located((By.XPATH, "//input[@name='flight_origin_date']"))).click()
wait.until(expected_conditions.visibility_of_any_elements_located((By.XPATH,"//td[@data-date]")))
dates = driver.find_elements_by_xpath("//td[@data-date]")
driver.execute_script("arguments[0].click()",random.choice(dates))
wait.until(expected_conditions.invisibility_of_element_located((By.XPATH,"//td[@data-date]")))
destination = wait.until(
expected_conditions.presence_of_element_located((By.XPATH, "//input[@name='flight_destination_date']"))).click()
wait.until(expected_conditions.visibility_of_any_elements_located((By.XPATH,"//td[@data-date]")))
dates = driver.find_elements_by_xpath("//td[@data-date]")
random.choice(dates).click()
wait.until(expected_conditions.invisibility_of_element_located((By.XPATH,"//td[@data-date]")))
driver.quit()
The above code assumes Chrome browser and ChromeDriver , however you can use different browser of your choice. 上面的代码假定使用Chrome浏览器和ChromeDriver ,但是您可以使用其他选择的浏览器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.