I've a web page with following template :
<body>
...
<a type="submit"....>
"A1"
</a>
<a type="submit"....>
"A2"
</a>
<a type="submit"....>
"A3"
</a>
<a type="submit"....>
"A4"
</a>
<a type="submit"....>
"A5"
</a>
...
</body>
I'm finding the all set of "buttons" by next query :
//a[@type='submit']
The question is , what should I add, in order to get a spesific button, let's say "A4"
10x
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.
Locating Strategies- (By XPath- Using text()) In this section, you will learn how to locate a particular web element by XPath- Using text() method. "text() method" is used to identify an element based on the text available on the web page.
XPath text() function is a built-in function of the Selenium web driver that locates items based on their text. It aids in the identification of certain text elements as well as the location of those components within a set of text nodes. The elements that need to be found should be in string format.
How can I find the XPath of a button inside a div? From the Elements panel in Chrome's Developer Tools, you can press Ctrl+F and enter an XPath to view the search results for an XPath selector.
Presuming there are no useful attributes on the a
elements (e.g. class
or id
), you can use the contains
XPath function:
//a[@type='submit' and contains(., "A4")]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With