Select span/td 标签附近的锚 Python

Select an anchor near a span/td tag with Selenium Python

使用 Python 和 Selenium,我想通过我的健身房网站预订每天固定时间的位置。每天提供的 classes 列表(提供的 classes 的数量因天而异)在 table 中。所有行元素都是相同的或动态的(无法预测,网站与许多体育馆共享)。 Link 保留 class 使用 SVG 图像和 'onclick' 事件。 predictable 的唯一项目是行标签('span' 标签)。

我找到了唯一的 'span' 标签

block = driver.find_element_by_xpath('//span[@title="CrossFit: 5:30 PM / Corona"]')

我试过使用找到的 span 标签作为起点 (parent_td = block.find_element_by_xpath("//td")),但也不成功。

我想要的 link 是这个 span 标签右边的两个单元格。如果我单击跨度标题,按两次 TAB,然后按 ENTER(人机交互),我就可以保留我的位置。

如何select这个靠近span标签的锚标签?

这应该对你有帮助:

from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains

actions = ActionChains(driver) 

block.click() #Clicks on the title

actions.send_keys(Keys.TAB * 2) #Presses the tab key 2 times
actions.send_keys(Keys.ENTER) #Presses the enter key

actions.perform() #Performs these 2 actions sequentially