Hi I am new to python and 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. 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.