Home > other >  Xpath for element without unique Id or text argument
Xpath for element without unique Id or text argument

Time:05-21

I have this HTML definition and I'm getting mad trying to click "Search" button:

<tbody>
    <tr>
         <td>
             <button  type="button" style="width: 75px">Search</button>
         <td>
    </tr>
    <tr>
         <td>
             <button  type="button" style="width: 75px">Remove</button>
         <td>
    </tr>
</tbody>

The point here is that the buttons do not have a "Text" argument or unique identifier, just the texts 'Search' or 'Remove. I'm using robotframework with selenium library. things already tried (unsuccessfully):

Click Button //button[@type='button']/span[.='Search']

Click Button //button[@type='button']/span[.='Search']/.

Click Button //span[contains(text()='Search')]

Click Button //button[@type, 'button' and text()='Search']

Click Button //button[@type='button' and contains(.,'Search')]

Click Button //button[@type='button' and span='Search']

Click Button //html/body/*[contains(text()='Search')]

Click Button //span[text()='Search']/input[@type="radio"]

Click Button //span[text()='Search']

Click Button //span[label[text()='Search']]/input[@type="radio"]

Click Button //button[.//text()='Search']

Click Button //button[nomralize-space()='Search']

Click Button //html/body/*[., 'Search']

Click Button //button[.,'Search']

Click Button //span[.,'Search']

Click Button //button/span[text()='Search']

thanks in advance!

CodePudding user response:

This should work if there are no similar elements in your HTML.

Click Element    xpath=//button[contains(text(), 'Search')]

CodePudding user response:

You can try

Press Keys        <xpath>       //13

or the Solution provided by Ruben in earlier comment.

CodePudding user response:

Bad practics (although inner-text using is also bad practics - choose what is more suitable), but you can use searching by order:

//tbody/tr[1]//button

  • Related