0

I have a page that has a table with different rows. I need to click on a button that is on a specific row as this:

<tr  valign="top" >
<td>Need to click this row button</td>
<td  width="100px" >
<select  name="aaaamm1" >
<option  value="specific_value_1.php" >1</option>
<option  value="specific_value_2.php" >2</option>
<option  value="specific_value_3" >3</option>
</select>
   </td>
<td  width="60px" >
    
<input  type="button" onclick="javascript:function);" value="Ver">
</td>
</tr>

<tr  valign="top" >
<td  >Another row</td>
...

I can't identify this specific row and click on that button, I'm using selenium on python.

Trying to click on the button inside an specific row of a table.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

Given the HTML...

<tr  valign="top" >
    <td>Need to click this row button</td>
    <td  width="100px" >
        <select  name="aaaamm1" >
            <option  value="specific_value_1.php" >1</option>
            <option  value="specific_value_2.php" >2</option>
            <option  value="specific_value_3" >3</option>
        </select>
    </td>
    <td  width="60px" >
        <input  type="button" onclick="javascript:function);" value="Ver">
    </td>
</tr>

To identify and click on the element:

<td>Need to click this row button</td>

You can use either of the following locator strategies:

  • Using xpath, preceding-sibling and <select> tag:

    driver.find_element(By.XPATH, "//td[.//select[@name='aaaamm1']]//preceding-sibling::td[1]").click()
    
  • Using xpath, preceding-sibling and <input> tag:

    driver.find_element(By.XPATH, "//td[.//input[@value='Ver']]//preceding-sibling::td[2]").click()
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352