jquery - 无法使用多个类和跳过元素将 CSS 重写为 XPATH

标签 jquery python css selenium xpath

我正在尝试将 css 重写为 XPATH。 CSS 缩短为:

div:nth-child(1) > .lay-selection-button span.bet-button-price

我正在尝试编写一个 xpath 等效项。

//div[1]/button[starts-with(@class=’lay-selection-button span.bet-button-price’)]//span[@class=’bet-button-price’]

知道为什么它不起作用。

从这里site或者图像是 here

完整的 CSS 是:

#main-wrapper > div > div.scrollable-panes-height-taker > div > div.page-content.nested-scrollable-pane-parent > div > div > div > div.content-page-center-column.coupon-center-column > div > div:nth-child(1) > main > ng-include:nth-child(3) > section.coupon-card.coupon-card-first > div.card-content > bf-coupon-table > div > table > tbody > tr:nth-child(1) > td.coupon-runners > div:nth-child(1) > button.bf-bet-button.lay-button.lay-selection-button > div > span.bet-button-price

缩短为:

 div:nth-child(1) > button.bf-bet-button.lay-button.lay-selection-button > div > span.bet-button-price

最后是顶部的内容:

div:nth-child(1) > .lay-selection-button span.bet-button-price

最佳答案

你可以获得所有的price带有以下代码的第一个蓝色列中的值:

for cell in driver.find_elements_by_xpath('//div[1]/button[@price][1]'):
    print(cell.get_attribute('price'))

对于第一个粉色列:

for cell in driver.find_elements_by_xpath('//div[1]/button[@price][2]'):
    print(cell.get_attribute('price'))

如果你想得到size值而不是 price - 只需替换 cell.get_attribute('price')cell.get_attribute('size')

您可以使用 //div[2]从第二个蓝色/粉色列中获取值,//div[3]获取第三个值

关于jquery - 无法使用多个类和跳过元素将 CSS 重写为 XPATH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46903491/

相关文章:

javascript - 仅为屏幕阅读器隐藏文本

javascript - CSS移动背景图片

javascript - 有没有办法防止 jQuery 事件冒泡到特定的 div?

javascript - 哪个 HTML 元素的事件是 asp :RegularExpressionValidator client side validation bound?

python - Tkinter create_line问题: wrong # coordinates: expected an even number

Python 使用 writerow 将两个具有不同值类型的字典写入单个 csv 文件

javascript - 如何让这个脚本执行其他功能

javascript - 多次滑动函数调用

python - 将SQLalchemy查询结果传递给scrapy中的start_urls

css - SVG 相互覆盖 CSS 样式