【发布时间】:2023-03-05 07:16:01
【问题描述】:
These are the buttons I want selenium to click on
This is what the elements of the 4 buttons showed above look like
想让 selenium 用下面的元素点击这个按钮:
<div id="book_e43c607b-0fba-472e-ab84-7dd8ff6efb6b" class="time-slot"
data-slotclub="calgary" data-slotdate="Saturday, 17 July 2021"
data-slottime="at 5:00 PM">
<div class="time-slot-clock"></div>
<div class="time-slot-box">
<div class="time-slot-data-line">Saturday, 17 July 2021</div>
<div class="time-slot-data-line">at 5:00 PM</div>
<div class="time-slot-data-line">Click to reserve</div>
</div>
然而,与其使用 XPath 或类来查找按钮,我想看看是否有办法使用上面块中第三行的“data-slottime="at 5:00 PM"”部分。 我尝试使用下面的代码单击按钮,但是找不到元素。
time = driver.find_element_by_link_text("at 8:00 AM")
driver.execute_script("arguments[0].click();", time)
这个代码虽然有效,但使用了我不感兴趣的唯一 x 路径:
time = driver.find_element_by_xpath("//*[@id=\"book_1178d802-ba18-4742-9dce-aac877ad3efb\"]/div[2]/div[1]")
driver.execute_script("arguments[0].click();", time)
【问题讨论】:
标签: python selenium selenium-webdriver xpath selenium-chromedriver