首页 > 解决方案 > About xpath in table java

问题描述

I am trying to find the xpath of the button(its an input for real) from the name of the person in the corresponding line.

the right "connection" button from the name.

I have tried several xpath may saucun do not click the button I want.

It Clicks on the first button of the whole table each time

I tried this:

*d.driver.findElement(By.xpath("//tr/td[contains(text(), 'TOTO')]/following-sibling::td/input"));

and

*d.driver.findElement(By.xpath("//td[contains(text(), 'TOTO')]/following-sibling::td/input"));

and

*d.driver.findElement(By.xpath("//tr/td[contains(text(), 'TOTO')]/following-sibling::td/input[type='submit']"));

and

*d.driver.findElement(By.xpath("//tr/td[contains(text(),'TOTO')]//td[5]/input"));

I enclose the table.

Here is the HTML code :

<tr>
        <td>FR1547</td>
        <td>CAILLOUX</td>
        <td>CHRISTIANE</td>
        <td></td>
        <td></td>
        <td>UTILISATEUR</td>
        <td><input value="connection" onclick="document.getElementById('hiddenCuid').value = 'FR1547'" type="submit"></td>
    </tr>
    <tr>
        <td>US7784</td>
        <td>TOTO</td>
        <td>CHRISTINE</td>
        <td></td>
        <td></td>
        <td>UTILISATEUR</td>
        <td><input value="connection" onclick="document.getElementById('hiddenCuid').value = 'US7784'" type="submit"></td>
    </tr>

Second button :

<tr>
    <td>US4487</td>
    <td>PONT</td>
    <td>CHRISTIANE</td>
    <td></td>
    <td></td>
    <td>UTILISATEUR, MANAGER</td>
    <td><input value="connection" onclick="document.getElementById('hiddenCuid').value = 'US4487'" type="submit"></td>
</tr>

enter image description here

标签: htmlseleniumselenium-webdriverxpath

解决方案


try this xpath :

//td[text()='TOTO']/parent::tr/child::input

推荐阅读