i have button for language change, I want to click on the button regardless of the button text. i am able to do it but separately for both EN and AR, is there a way write the ONE xpath that will work in these two condition.
//span[contains(text(),'الإنجليزية')]
//span[contains(text(),'AR')]
CodePudding user response:
Yes, there is way you can use the below, this will work in both EN and AR.
//span[contains(text(),'الإنجليزية') or contains(text(),'AR')]
Also, you can learn it from
https://www.browserstack.com/guide/xpath-in-selenium
CodePudding user response:
You should not be using text in these types of situations. Avoid having a dependency on the text. Use other HTML attribute such as id
, type
, value
, placeholder
, class
etc. which is common in both the language.
however, you could do use or
in XPath:
//span[contains(text(),'الإنجليزية') or contains(text(),'AR')]
CodePudding user response:
You can use Boolean or
operator with XPath expression.
So your XPath could be
"//span[contains(text(),'الإنجليزية') or contains(text(),'AR')]"