How to shorten xpath for multilingual support having same attribute with multiple values but using contains function?

29 views Asked by At

Earlier my xpath for a certain image element was written with text containing English words.

Now, with vernacular support it has lengthened. Seeking help to shorten it.

XPath with English support:

//android.widget.TextView[contains(@text,'Web') and contains(@text,'Result')]/preceding-sibling::android.widget.ImageView[@index=0];

XPath supporting Tamil as well:

//android.widget.TextView[(contains(@text,'வெப்') or contains(@text,'Web')) and (contains(@text,'விளைவாக') or  contains(@text,'Result') )]/preceding-sibling::android.widget.ImageView[@index=0];

Is there any way I can shorten the above Xpath ? Something like below (but not exactly using pipe):

//android.widget.TextView[contains(@text,'Web'|'வெப்') and contains(@text,'Result'|'விளைவாக')]/preceding-sibling::android.widget.ImageView[@index=0];
1

There are 1 answers

0
Martin Honnen On

There is the XPath 2.0 matches function e.g. matches(@text,'வெப்|Web').