RE: [Selenium-users] How to select a particular checkbox within a table? javascript attempted

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

RE: [Selenium-users] How to select a particular checkbox within a table? javascript attempted

Paatsch, Bernd
How to select a particular checkbox within a table?
I am not a java programmer but I believe I can solve my problem extending selenium's ser-extensions.js with following code:
 
What do the javascript people think about the code option?

Selenium.prototype.findGroupCheckBox(text) {
  //returns the value of the the chechbox by name
  var value;
 
  //find all anchor elements
  var elements = this.page().findElement('a');
 
  for (n in elements) {
   // if text is in element then the value of value needs to be returned out
   if(elements.search(text)) != -1) {
  var start = elements[n].lastIndexOf('=');
  var end = elements[n].lastIndexOf('"');
  value = elements[n].slice(start, end);
  return value;
 }
  }
 
  return null;
 
}
 
 


From: [hidden email] [mailto:[hidden email]] On Behalf Of Paatsch, Bernd
Sent: Friday, January 13, 2006 11:24 AM
To: [hidden email]; [hidden email]
Subject: [Selenium-users] How to select a particular checkbox within a table?

I like to select one particular checkbox. The only reference I have is the name "first" or " second" as you can see in the html sample code.

The value attribute unfortunately is driven by an database and changes. Therefore I can not say that value="70" is always the first checkbox.

So the only way I can select the right checkbox is looking for the name "first/second" and then select the prior table cell checkbox.

Xpath buffs is there a way to do that?

I tried:

<td>storeAttribute</td>
<td>//tr[position()>1]/td[2][a=first]/preceding-sibling::tr/input@value</td>
<td></td>




HTML-code-sample:

<tbody>
<tr class="table_header">
        <th title="Mark group for deletion"></th>
        <th title="Click to view group properties">Name</th>
        <th>Type</th>
</tr>
<tr>
        <td><input name="cbxSelectGroup[]" value="70" type="checkbox"></td>
        <td><a href="group_example.php?id_group=70">first</a></td>
        <td>Dispatch</td>
</tr>
<tr>
        <td><input name="cbxSelectGroup[]" value="69" type="checkbox"></td>
        <td><a href="group_example.php?id_group=69">second</a></td>
        <td>Dispatch</td>
</tr>
</tbody>

***************************************
Bernd Paatsch