0

I am in search of conditional XPath syntax. My xpath is as follows:

//div[@id='contenttext']/form/table/tbody/tr[7]/td[2]/input[1]

Now the scenario is that the above mentioned input field can be found at tr[7] (already mentioned) and tr[6]. So in brief I need one syntax to test that the input field should be present either at tr[7] or tr[6]. i.e.:

//div[@id='contenttext']/form/table/tbody/tr[7]/td[2]/input[1]
//div[@id='contenttext']/form/table/tbody/tr[6]/td[2]/input[1]

Both the above mentioned XPath should be combined and the test should return true if the input[1] is present at either tr[7] or tr[6].

PS: tr[position()=7 or position()=6] is not working. The code tries to find the element at lower position mentioned. i.e tr[6]

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Suhird Singh
  • 121
  • 2
  • 14

2 Answers2

1

You can use pipeline syntax (|) here as below :

//div[@id='contenttext']/form/table/tbody/tr[7]/td[2]/input[1]|//div[@id='contenttext']/form/table/tbody/tr[6]/td[2]/input[1]
Pratik G
  • 99
  • 2
  • 1
    The `|` operator is the `union` operator not "pipeline syntax", see: http://www.w3.org/TR/xpath-functions/#func-union. Also you can shorten your expression by rewriting it to remove the common stem: `//div[@id='contenttext']/form/table/tbody/(tr[6] | tr[7])/td[2]/input[1]` – adamretter May 15 '14 at 10:14
0

the position method can be provided a range ...

tr[position() >= 6 and not(position() > 7)]

excerpt from What is the xpath to select a range of nodes?

Community
  • 1
  • 1
Kenneth Clark
  • 1,725
  • 2
  • 14
  • 26