[英]Unable to scroll down the calendar while automate the Yatra.com (Selenium webdriver using python)
[英]Select date from date picker in yatra.Com
嗨,我是python和Selenium的新手。 我是出於興趣而學習它。 我的問題是我想在下面的網站中選擇出發日期和到達日期。 https://www.yatra.com/我需要使用selenium的python中的代碼,任何人都可以幫助我。 如果需要,您可以使用任何其他庫。
感謝您的協助。
示例代碼:
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()
上面的代碼假定使用Chrome瀏覽器和ChromeDriver ,但是您可以使用其他選擇的瀏覽器。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.