Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find XPath attribute name contains specific string

Tags:

xpath

I have <form data-v-4db188a6=""> tag. I need find only form tag contains 'data' in the attribute name not attribute value! .//form[contains(@prop, 'data')] not work. Is it even possible?

like image 591
pwb Avatar asked Dec 05 '17 09:12

pwb


People also ask

How use attribute for contain in XPath?

Using the XPath contains() function, we can extract all the elements on the page that match the provided text value. Here, tag: tag is the name of the tag that contains the specific word. word: In this case, the word refers to the text that must be discovered in a specific string.

How do I find the XPath of a tag name?

Go to the First name tab and right click >> Inspect. On inspecting the web element, it will show an input tag and attributes like class and id. Use the id and these attributes to construct XPath which, in turn, will locate the first name field.

How do you locate an element by partially comparing its attributes in XPath?

We can identify elements by partially comparing to its attributes in Selenium with the help of regular expression. In xpath, there is contains () method. It supports partial matching with the value of the attributes. This method comes as useful while dealing with elements having dynamic values in their attributes.

What does * indicate in XPath?

By adding '//*' in XPath you would be selecting all the element nodes from the entire document. In case of the Gmail Password fields, .//*[@id='Passwd'] would select all the element nodes descending from the current node for which @id-attribute-value is equal to 'Passwd'.


1 Answers

Yes, this is possible:

//form[attribute::*[contains(local-name(), 'data')]]
like image 96
Keith Hall Avatar answered Jan 04 '23 00:01

Keith Hall