Home > OS >  Using or condition in Xpath Attributes
Using or condition in Xpath Attributes

Time:06-17

I have two different web pages and two different anchor tags First one is <a href="#" data-titlex ="some title" /> and the other one is <a href="#" data-titley ="some title" />.

I want to fetch the title of this anchor tag using selenium. I am aware that I can use or between classes

//*[@class= 'different_class_name' or @class='class_name']

But I am not able to figure how to do the same for fetching data attributes (data-titlex or data-titley).

CodePudding user response:

Try this one if you want predicate for 2 attribute with different names but the same values:

//a[@*[.='some title']]

or

//a[@*[starts-with(name(), 'data-title') and .='some title']]

CodePudding user response:

If you're trying to retrieve the value of attributes with either attribute name:

//a/@*[name() = 'data-titlex' or name() = 'data-titley']

The @* returns all attributes of each a. The predicate filters for those attributes with exactly those names.

  • Related