我正在尝试将 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’]
知道为什么它不起作用。
完整的 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/