简体   繁体   中英

Selenium Java Click Radio Button That is in a Table Row

So I'm pretty new to Selenium and I'm writing my first program with it. I'm trying to click a radio button that is on a table row. Here is the html code for the row.

<tbody>
   <tr id="headerrow">
      <td></td>
      <td align="center">Name</td>
      <td align="left">Account</td>
      <td align="center">Status</td>
      <td></td>
      <td align="center">CW</td>
      <td></td>
      <td align="center">Last Hit</td>
      <td></td>
      <td align="right">IP</td>
   </tr>
   <tr>
      <td height="1" bgcolor="#000000" colspan="10"></td>
   </tr>
   <tr>
      <td height="10" colspan="10"></td>
   </tr>
   <tr id="userrow_1">
<td><input type="radio" name="id" value="1764" onclick="set_it('1');"></td>
<td>John Doe</td>
<td>jdoe</td>
<td align="center" bgcolor="#CCFFCC">Active</td>
<td>&nbsp;</td><td align="center" bgcolor="ccffcc">Yes</td><td>&nbsp;</td><td align="center" nowrap="">Offline - 12/12/12</td><td>&nbsp;</td><td align="right">192.168.1.1</td></tr>
   </tbody>

I need to be able to click the button with only the value variable. Thanks for any help.

How about this:

driver.findElement(By.cssSelector("input[name='id'")).click();

This will click the radio button. input[name='id'] is the css selector, that will find your element. And click() method will click on it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM