質問

How can I create an Xpath for individual elements within the same class name? The element ids (eg. id='some_item_12') is not constant (ie. could be 12,3, etc on next iteration) so I can't use a direct xpath to the element.

I have used the one below but it fetches the first element in that class eg. //*[@id='someitem_12']/td[5]/div/a[1] while I want a[2]

//*[contains(concat(' ', normalize-space(@class), ' '), ' $classname ')]

Thanks.

LP

役に立ちましたか?

解決 2

I think I've got it but I'm sure there are better ways of doing it.

//*[contains(@id,'someitem_')]/a[2] //worked for me

他のヒント

Looks ok

You can also use findElements which will return a list of all elements. From there you can iterate on the result list and find the element you were looking for

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top