gpt4 book ai didi

javascript - 如何在 https ://www. expedia.co.in/using Selenium 内通过 Python 在 checkin 和 checkout 字段中发送不同的日期

转载 作者:行者123 更新时间:2023-11-30 06:15:25 24 4
gpt4 key购买 nike

我正在编写一个简单的代码来选择 Expedia 中的到达地点、出发地点、到达日期和离开日期。

一切正常,预计到达日期和离开日期显示相同

from selenium import webdriver
from selenium.webdriver.common.by import By
import time

driver = webdriver.Firefox(executable_path="C:/bin/geckodriver.exe")
driver.implicitly_wait(20)
driver.maximize_window()
driver.get("https://www.expedia.co.in/")
driver.find_element(By.ID, "tab-flight-tab-hp").click()
driver.find_element(By.ID, "flight-origin-hp-flight").send_keys("SFO")
time.sleep(2)
driver.find_element(By.ID, "flight-destination-hp-flight").send_keys("NYC")
driver.find_element(By.ID, "flight-departing-hp-flight").send_keys("07/06/2019")
time.sleep(2)
driver.find_element(By.ID, "flight-returning-hp-flight").clear()
driver.find_element(By.XPATH, "//input[@id='flight-returning-hp-flight']").send_keys("10/06/2019")
driver.find_element(By.XPATH,"//form[@id='gcw-flights-form-hp-flight']//button[@class='btn-primary btn-action gcw-submit']").click()

输出截图:

output screenshot

最佳答案

需要对用户脚本做一点改动。

输入开始日期后单击返回日期。然后按退格键删除默认日期。以下是逻辑。

driver.find_element(By.ID, "flight-departing-hp-flight").send_keys("07/06/2019")
ele = driver.find_element(By.ID, "flight-returning-hp-flight")
#click on return date field
ele.click()
# remove the default date(same as selected start date) by hitting backspace
length = len(ele.get_attribute('value'))
ele.send_keys(length * Keys.BACKSPACE)
#enter the return date
driver.find_element(By.XPATH, "//input[@id='flight-returning-hp-flight']").send_keys("10/06/2019")

关于javascript - 如何在 https ://www. expedia.co.in/using Selenium 内通过 Python 在 checkin 和 checkout 字段中发送不同的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56490114/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com