我有这个HTML:
<div tabindex="0" class="ember-basic-dropdown-trigger ember-power-select-trigger ember-power-select-trigger-2568211667 category-select t-ticket-category-select-trigger">
Building
</div>
<div tabindex="0" class="ember-basic-dropdown-trigger ember-power-select-trigger ember-power-select-trigger-6101225577 category-select t-ticket-category-select-trigger">
Warehouse
</div>
我想访问具有相同CSS类名的 2nd div中的文本,但我不确定如何访问它。
我有一些像这样的XPath代码,但这不起作用:
//*[contains(@class, 't-ticket-category-select-trigger')]
答案 0 :(得分:3)
只需通过索引访问(索引在XPath中以1开头):
(//*[contains(@class, 't-ticket-category-select-trigger')])[2]
或者,如果它是 last 那么:
(//*[contains(@class, 't-ticket-category-select-trigger')])[last()]