Selenium 无法从日期选择器中选择日期

发布于 2025-01-11 12:34:49 字数 1549 浏览 0 评论 0原文

无法从日期选择器中选择日期,

这是正在运行的网站 https://www.phptravels.net/

当我在 firebug 上使用开发人员选项和 Ctrl + F 时 //div[@style='显示:块;顶部:390 像素; left: 680px;']//text()[contains(.,'15')]

我能够在页面上找到日期

,但是当我尝试使用代码时,我无法选择元素

这是我的代码

self.driver.find_element(By.XPATH, "//div[@style='display: block; top: 390px; left: 680px;']//text()[contains(.,'"+start_date+"')]").click()


test_Flight.py:37: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\pages\search_flights_form.py:68: in set_start_date_pick
    self.driver.find_element(By.XPATH, "//div[@style='display: block; top: 390px; left: 680px;']//text()[contains(.,'15')]").click()
..\..\..\..\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py:976: in find_element
    return self.execute(Command.FIND_ELEMENT, {
..\..\..\..\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py:321: in execute
    self.error_handler.check_response(response)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x052D6D18>
response = {'status': 404, 'value': '{"value":{"error":"no such element","message":"Unable to locate element: //div[@style=\'disp...ntent/shared/webdriver/Errors.jsm:395:5\\nelement.find/</<@chrome://remote/content/marionette/element.js:300:16\\n"}}'}

unable to select a date from date picker

this is the website working on https://www.phptravels.net/

when i used developer options and Ctrl + F on firebug
//div[@style='display: block; top: 390px; left: 680px;']//text()[contains(.,'15')]

i am able to find the date on the page

but when i am trying from the code i am unable to select the element

This is my code

self.driver.find_element(By.XPATH, "//div[@style='display: block; top: 390px; left: 680px;']//text()[contains(.,'"+start_date+"')]").click()


test_Flight.py:37: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
..\pages\search_flights_form.py:68: in set_start_date_pick
    self.driver.find_element(By.XPATH, "//div[@style='display: block; top: 390px; left: 680px;']//text()[contains(.,'15')]").click()
..\..\..\..\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py:976: in find_element
    return self.execute(Command.FIND_ELEMENT, {
..\..\..\..\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\remote\webdriver.py:321: in execute
    self.error_handler.check_response(response)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x052D6D18>
response = {'status': 404, 'value': '{"value":{"error":"no such element","message":"Unable to locate element: //div[@style=\'disp...ntent/shared/webdriver/Errors.jsm:395:5\\nelement.find/</<@chrome://remote/content/marionette/element.js:300:16\\n"}}'}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

李不 2025-01-18 12:34:49

尝试如下并确认。

driver.get("https://www.phptravels.net/")

wait = WebDriverWait(driver,30)

checkin = wait.until(EC.element_to_be_clickable((By.ID,"checkin")))
checkin.click()

date = 15
select_date = wait.until(EC.element_to_be_clickable((By.XPATH,f"//div[@class='datepicker-days']//td[text()='{date}']")))
select_date.click()

更新:根据评论从航班部分选择日期。

driver.get("https://www.phptravels.net/")

wait = WebDriverWait(driver,30)

flights = wait.until(EC.element_to_be_clickable((By.XPATH,"//button[@aria-controls='flights']")))
flights.click()

departure_date = wait.until(EC.element_to_be_clickable((By.XPATH,"//input[contains(@class,'depart')]")))
departure_date.click()

date = 15
select_date = wait.until(EC.element_to_be_clickable((By.XPATH,f"(//div[@class='datepicker-days'])[3]/table/tbody/tr[3]/td[text()='{date}']")))
select_date.click()

Try like below and confirm.

driver.get("https://www.phptravels.net/")

wait = WebDriverWait(driver,30)

checkin = wait.until(EC.element_to_be_clickable((By.ID,"checkin")))
checkin.click()

date = 15
select_date = wait.until(EC.element_to_be_clickable((By.XPATH,f"//div[@class='datepicker-days']//td[text()='{date}']")))
select_date.click()

Update: As per comments to select date from Flights section.

driver.get("https://www.phptravels.net/")

wait = WebDriverWait(driver,30)

flights = wait.until(EC.element_to_be_clickable((By.XPATH,"//button[@aria-controls='flights']")))
flights.click()

departure_date = wait.until(EC.element_to_be_clickable((By.XPATH,"//input[contains(@class,'depart')]")))
departure_date.click()

date = 15
select_date = wait.until(EC.element_to_be_clickable((By.XPATH,f"(//div[@class='datepicker-days'])[3]/table/tbody/tr[3]/td[text()='{date}']")))
select_date.click()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文