无法使用日期填写两个输入框 [英] Unable to fill in two inputboxes with dates
问题描述
我一直在尝试用日期填充两个输入框(其余的已经填充),然后单击Search Flights
按钮填充结果,但无法完成.我已注释掉脚本中未成功的尝试.
I've been trying to fill in two inputboxes with dates (the rest are already filled in) before clicking on the Search Flights
button to populate the result but can't make it. I've commented out the unsuccessful attempt in my script.
我希望输入框填充以下日期19 Jan, 19
和7 Feb, 19
.
I would like the inputboxes to be filled with the following dates 19 Jan, 19
and 7 Feb, 19
.
到目前为止,我的尝试:
My attempt so far:
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 as EC
from selenium.webdriver.common.keys import Keys
def fill_in_search_boxes(driver,url):
driver.get(url)
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, ".airportselector_input[placeholder='From']"))).send_keys("Tatry - Poprad")
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, ".airportselector_input[placeholder='To']"))).send_keys("London")
# wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, ".od-ui-datepicker-display"))).send_keys("Sat. 19 Jan, '19")
# wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, ".od-ui-datepicker-display"))).send_keys("Thu. 7 Feb, '19")
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, ".od-flightsManager-search-flight-button"))).click()
if __name__ == '__main__':
url = "https://www.edreams.com/"
driver = webdriver.Chrome()
wait = WebDriverWait(driver,10)
try:
fill_in_search_boxes(driver,url)
finally:
driver.quit()
推荐答案
您正在尝试将密钥发送到div
而不是input
字段.您需要单击每个div
并选择所需的日期.
You're trying to send keys to div
, not to input
field. You need to click each div
and select required date.
请尝试以下操作以获取所需的输出.
Try below to get required output.
def fill_in_search_boxes(driver,url):
driver.get(url)
# Select first airport
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".airportselector_input[placeholder='From']"))).send_keys("Tatry - Poprad")
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[.='Tatry - Poprad']"))).click()
# Select second airport
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".airportselector_input[placeholder='To']"))).send_keys("London")
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[.='London']"))).click()
# Select From date
wait.until(EC.presence_of_element_located((By.XPATH, "//div[.='Departure']"))).click()
wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'day_2019-01-19'))).click()
# Select To date
wait.until(EC.presence_of_element_located((By.XPATH, "//div[.='Return']"))).click()
wait.until(EC.element_to_be_clickable((By.CLASS_NAME, 'day_2019-02-07'))).click()
# Submit form
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, ".od-flightsManager-search-flight-button"))).click()
请注意,这允许处理当前/下个月的日期.您可能需要创建一个函数来处理所有月份的日期.
Note that this allows to handle dates from current/next month. You might need to create function that will handle dates from all months.
P.S.由于验证码原因,我无法检查此代码,所以请告诉我它是否有问题
P.S. I cannot check this code due to CAPTCHA, so let me know if something wrong with it
这篇关于无法使用日期填写两个输入框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!