Jquery 无法使用多个类和跳过元素将CSS重写为XPATH
我正在尝试将css重写为XPATH。css缩短为:Jquery 无法使用多个类和跳过元素将CSS重写为XPATH,jquery,python,css,selenium,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’] 知道它为什么不起作用吗 它是从这个或一个图像是
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
您可以使用以下代码从第一个蓝色列中获取所有
价格值:
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
-只需将单元格。获取属性(“price”)
替换为单元格。获取属性(“size”)
您可以使用//div[2]
从第二个蓝色/粉色列获取值,//div[3]
从第三个蓝色列获取值您可以使用以下代码从第一个蓝色列获取所有价格
值:
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
-只需将单元格。获取属性(“price”)
替换为单元格。获取属性(“size”)
您可以使用//div[2]
从第二个蓝色/粉色列获取值,使用//div[3]
获取第三个列的值
//tr//*[contains(@class,'coupon-runner')][1]/button[2]//span[contains(@class,'bet-button-price')]
以下是xpath,不是为了编写其他代码:
//tr//*[contains(@class,'coupon-runner')][1]/button[2]//span[contains(@class,'bet-button-price')]
使用以下css时将获得多少个按钮:button.lay-selection-button span.bet-button-price?您的xpath似乎不正确:您可以尝试以下方法://div[1]/button[以(@class='lay-selection-button')开头]//span[@class='bet-button-price']您想要哪个输出?仅表中的第一个值(当前为1.01
)?使用contains函数://div[1]/button[contains(@class,'lay-selection-button')如何//span[@class='bet-but关于价格“]我想到了上面的第一个蓝色:)你只需要粉红色吗?或者两者都有?当使用以下css时,您将得到多少个按钮:button.lay-selection-button span.bet button price?您的xpath似乎不正确:您可以尝试以下命令://div[1]/button[以(@class='lay-selection-button')开头]//span[@class='bet button-price']您想要哪个输出?仅表中的第一个值(当前为1.01
)?使用contains函数://div[1]/button[contains(@class,'lay-selection-button')如何//span[@class='bet-but关于价格“]我想到了上面的第一个蓝色:)你只需要粉红色吗?或者两者都有?干杯。这也是编写它的一种有用方法(是的,定义文档的结构并从逻辑上遵循它)您还可以将其包装到方法和路径参数中,以tr、按钮和优惠券运行者位置
,因此基本上这个xpath将用于选择tableCheers中的任何单元格。这也是编写它的一种有用方法(是的,定义文档的结构并从逻辑上遵循它)您还可以将其包装到方法和路径参数中,以tr、按钮和优惠券运行者位置
,因此基本上这个xpath将用于选择表中的任何单元格