0

I have two possible xpaths on which I can find the solution. Is there a way with regex so that I can combine the 2 possible xpath in a single xpath string?

Suhird Singh
  • 121
  • 2
  • 13
  • What kind of a regex do you want to use? Can you tell which `tr` contains the data by something other than the index? If it's just the index, you can use the `position()` function in a predicate. `tr[position() = 6 or position() = 7]` – toniedzwiedz Apr 24 '14 at 06:12
  • For example that I am testing the value of a textbox which might be present in 3rd row or the 6th row of the table. So for the indexing of the tr tag is there any regular expression that can be embedded in the xpath? – Suhird Singh Apr 24 '14 at 06:14
  • 2
    You could see if the `position()` of the `tr` tag representing the row is equal to 3 or 6, as explained above. I don't know of any way to do it with a regular expression. As for your updated question, it is possible to combine multiple XPath expression into a single one. Take a look at [this answer to a different question](http://stackoverflow.com/a/11040630/1407656) – toniedzwiedz Apr 24 '14 at 06:34
  • Css selectors may be a solution rather then xpath as they support nth-of-type. Without seeing your HTML, it is impossible to offer a concrete answer – Robbie Wareham Apr 24 '14 at 06:46
  • Thanks a ton Tom. That really helped me alot. I wanted a sort of OR condition between 2 xpath and it should also be combined into a single xpath string. – Suhird Singh Apr 24 '14 at 07:12

1 Answers1

2

There is an or operator in xpath.

For instance, this will find all book or all chapter nodes:

//book|//chapter

In general to or two nodesets with query_a and query_b just do:

query_a|query_b
Community
  • 1
  • 1
Mike H-R
  • 7,147
  • 5
  • 37
  • 58