-1

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

L P
  • 1,776
  • 5
  • 25
  • 46
  • There are lots of ways it could be done - but without seeing more of the html to understand the structure, it's difficult to recommend any one way of doing it. – Vince Bowdren Jun 07 '13 at 13:15
  • I'll explain the scenario: I have a set of rules that I can add to a Rule_list and each rule created has an edit and delete button. Assume that's what needs automation ie. creating a rule, editing it and deleting it after verifying the working functionality. The issue here is that each time I want to delete the rule, the button's name "rule_input_id" keeps changing ie. it's rule_input_12 or 2 etc so the test fails. How would you suggest going about that? – L P Jun 12 '13 at 09:40

2 Answers2

1

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

Ittiel
  • 1,104
  • 9
  • 12
0

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

L P
  • 1,776
  • 5
  • 25
  • 46