我想使用Python和Selenium,每天在健身房的网站上保留一个固定的时间。每天提供的课程列表(每天提供的课程数量各不相同)在表格中。所有行元素都是相同或动态的(无法预测,站点与许多体育馆共享)。链接到保留类使用SVG图片和“ onclick”事件。唯一可预测的项目是行标签(“ span”标签)。
我设法找到了唯一的“ span”标签
block = driver.find_element_by_xpath('//span[@title="CrossFit: 5:30 PM / Corona"]')
我尝试使用找到的span标签作为起点(parent_td = block.find_element_by_xpath("//td")
),但也没有运气。
我想要的链接是此span标签右侧的两个单元格。如果单击跨度标题,请按两次TAB键,然后按ENTER键(人机交互),则可以保留我的位置。
如何选择靠近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
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句