我正在尝试获取此website的此css_selector的xpath等效项。
要添加6个元素:div:nth-child(1)
。对于xpath,它将是//div[1]
但这没有区别。我想要左侧结果tab
的CSS:
div:nth-child(1) > proposition-return > div > animate-odds-change > div > div
返回6个元素
xpath(非常相似):
//div[@class='propositions-wrapper'][1]//div[contains(@class, 'proposition-return')]//animate-odds-change//div//div
返回18
我希望6.
<div ng-repeat="odd in odds" class="animate-odd ng-binding ng-scope" ng-class="{
'no-animation': oddsShouldChangeWithoutAnimation
}" style="">2.05</div>
答案 0 :(得分:0)
那些是完全不同的选择者:
CSS: div:nth-child(1) > proposition-return > div > animate-odds-change > div > div
查找作为其父级的第一个子级的每个
div
,然后获取其直接proposition-return
子级(我假设您希望像.proposition-return
一样使用它,然后直接{{1}等等..
XPATH: div
以
//div[@class='propositions-wrapper'][1]//div[contains(@class, 'proposition-return')]//animate-odds-change//div//div
作为类查找所有div
个元素,然后只获取第一个元素。之后,找到所有proposition-wrapper
的{{1}}类,它们是前一个元素的后代,依此类推......
div
与proposition-return
非常不同,[1]
与nth-child(1)
不同,但//
是。
为了获得你想要的特定元素,我会使用这个xpath:
>
答案 1 :(得分:0)
该网站在全球范围内无法使用,但查看您提供的图片会有所帮助。正如eLRuLL指出的那样,你的xpath不等同于css。
尝试摆脱一些双斜线
//div[@class='propositions-wrapper']//div[contains(@class, 'proposition-return')]/animate-odds-change/div/div[contains(@class, 'animate-odd')]