Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xpath : Get a button by type and text

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

like image 410
Igal Avatar asked Jun 07 '13 10:06

Igal


People also ask

How can I find the XPath of a button?

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.

Can we use text () in XPath?

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.

What is text () function in XPath?

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?

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.


1 Answers

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")]
like image 115
lonesomeday Avatar answered Oct 07 '22 18:10

lonesomeday