首页 > 解决方案 > 如何用硒单击表格中的元素?

问题描述

我想选择可用的约会

from selenium import webdriver
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)

driver.get("https://vadmvappointments.as.me/schedule.php?calendarID=5322490")

element = driver.find_elements_by_xpath(//*[@id="step-pick-appointment"]/div[2]/div[4]/div[1]/table[2]/tbody/tr[4]/td[2])

element.click()

标签: pythonselenium

解决方案


cp的东西...

您的 xpath 缺少将其括起来的双引号...

所以代替这个:

element = driver.find_elements_by_xpath(//*[@id="step-pick-appointment"]/div[2]/div[4]/div[1]/table[2]/tbody/tr[4]/td[2])

用这个:

element = driver.find_elements_by_xpath("//*[@id='step-pick-appointment']/div[2]/div[4]/div[1]/table[2]/tbody/tr[4]/td[2]")

请注意我也更改find_elements_by_xpathfind_element_by_xpath,它是单个元素。

但是,您发送的那个链接返回“没有可用的约会”,所以即使xpath是正确的,它也不会工作


推荐阅读