3

How to find the attribute is available or not in particular element?

Antony
  • 966
  • 8
  • 19
  • Possible duplicate of [Checking presence of attribute with cts:query](http://stackoverflow.com/questions/21434099/checking-presence-of-attribute-with-ctsquery) – Ankit Bhardwaj Apr 21 '16 at 03:39

2 Answers2

4

Use XPath that will return your target attribute and convert the result to boolean :

boolean(//target_element/@target_attribute)

or similar approach but using exists() function :

exists(//target_element/@target_attribute)

Actually, the context isn't clearly stated in the question, for example, maybe the context element in your case is the target element already, so you don't need //target_element/ part.

har07
  • 88,338
  • 12
  • 84
  • 137
0

Also, you can return all of the attribute names for the target element:

//target-element/(@*[1])
Kindle Q
  • 944
  • 2
  • 19
  • 28