从共享主干、python selenium 的元素中查找 XPATH 按钮
我正在尝试做与此博客文章相同的( https://tmonty.tech/create-an-automated-web-bot-with-selenium-in-in-python )在我的大学中,但我正在努力,作为一个完整的菜鸟。我想知道是否有人可以迅速看我的问题。基本上,我的大学正在将预订组织成桌子的格式。例如(下图),我想在3月31日星期四的12:15预订旋转。单词旋转的X Path是:
`//\*\[@id="booking-details"\]/tbody/tr\[7\]/td\[2\] and it's element is : \<td data-bind="text: name" class="name"\>Spinning\</td\>`
选择按钮的XPath是:
//\*\[@id="booking-details"\]/tbody/tr\[7\]/td\[6\]/a and it's element is : <a class="btn primary-color select-booking" data-bind="attr: { 'data-id': id, 'data-start': start }" data-id="SWKPV9ON1SVO9QY" data-start="Thu Mar 31 2022 07:15:00 GMT+0000">SELECT</a>
我不能简单地搜索时间,因为Zumba和Spinning俩都是那个时间。也有多个旋转。但是我想要的旋转和我的按钮具有相同的开始,
/\*\[@id="booking-details"\]/tbody/tr\[7\]/
您知道我如何找到与两者匹配并使用它来找到按钮的X Path的开头?该表是动态的,并且会根据日期和可用性变化。
任何帮助将不胜感激!!
我尝试了contains(text)函数,但不能让它搜索活动和日期
I am trying to do the same as this blog post (https://tmonty.tech/create-an-automated-web-bot-with-selenium-in-python)in my university but I am struggling with it, as a complete noob. I wondered if anyone could quickly look at my problem. Basically, my University is organizing the bookings into a table format. As an example (below) I would like to book Spinning at 12:15 on Thursday 31st of March. The XPATH for the word Spinning is:
`//\*\[@id="booking-details"\]/tbody/tr\[7\]/td\[2\] and it's element is : \<td data-bind="text: name" class="name"\>Spinning\</td\>`
The XPATH for the Select button is:
//\*\[@id="booking-details"\]/tbody/tr\[7\]/td\[6\]/a and it's element is : <a class="btn primary-color select-booking" data-bind="attr: { 'data-id': id, 'data-start': start }" data-id="SWKPV9ON1SVO9QY" data-start="Thu Mar 31 2022 07:15:00 GMT+0000">SELECT</a>
I can't simply search for the time as Zumba and Spinning are both that time. There are multiple Spinning as well. But the Spinning I want and my button have the same beginning
/\*\[@id="booking-details"\]/tbody/tr\[7\]/
Do you know how I could find the beginning of the XPATH that matches both and use that to find the button? The table is dynamic and changes according to date and availability.
Any help would be greatly appreciated!!!
I have tried the contains(text) function but can't get that to search for both activity and date
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我设法解决了我的问题: driver.find_element_by_xpath("//tbody/tr/td[contains(text(), 'Spinning')]/../td[6]/a[@data-start=' Thu Mar 31 2022 12:15:00 GMT+0000']”事实上,我通过搜索日期、班级和时间来改进这一点,如下所示: ((By.XPATH,'//tbody/tr/td/span[包含(text(), "星期三")]/../../following-sibling::tr/td[包含(text(), "旋转")]/../td[包含(text(),"17:15")]/../td[6]/a'))).click()
I managed to solve my problem with this: driver.find_element_by_xpath("//tbody/tr/td[contains(text(), 'Spinning')]/../td[6]/a[@data-start='Thu Mar 31 2022 12:15:00 GMT+0000']" in fact, i improved this with searching for day, class and time instead like this: ((By.XPATH,'//tbody/tr/td/span[contains(text(), "Wednesday")]/../../following-sibling::tr/td[contains(text(), "Spinning")]/../td[contains(text(),"17:15")]/../td[6]/a'))).click()