2

I do have the following html text:

<tr class="off" onmouseout="this.className='off'"onmouseover="this.className='over'">
<td><input type="checkbox" name="caller_enrollment_form:enrollmentParticipantSelectionTable:0:personSelecti‌​on" id="caller_enrollment_form:enrollmentParticipantSelectionTable:0:personSelection‌​" value="true" />
</td>
<td><span id="caller_enrollment_form:enrollmentParticipantSelectionTable:0:extClientId">11‌​1</span>
</td>
<td><span id="caller_enrollment_form:enrollmentParticipantSelectionTable:0:clientName">SAM‌​UEL</span>
</td>

I am trying to click on the checkbox which has the data 111 in the same row.

I am trying to something like this:

page.FindChildByXPath("//span[contains(text(),'111')]/parent::td/preceding-sibling::td/input[@name='caller_enrollment_form:enrollmentParticipantSelectionTable:0:personSelection']",false)

but I get object not found error.

JackWhiteIII
  • 1,388
  • 2
  • 11
  • 25
test
  • 21
  • 1
  • Welcome to StackOverflow. I have merged your HTML into the question and added some more appropriate tags. You can add things to improved the detail in the question by clicking on the [edit] button like I did. Hope you find your answer. – Brian Tompsett - 汤莱恩 Jun 15 '15 at 22:16

1 Answers1

0

Your checkox has an ID, and IDs are unique within a page. So you can use:

// JScript
var checkBox = page.FindChildByXPath("//input[@id='caller_enrollment_form:enrollmentParticipantSelectionTable:0:personSelection‌​']");
checkBox.ClickChecked(true); // Check the checkbox

The ID contains a number (0); you can use a variable to specify this number:

var checkBox = page.FindChildByXPath("//input[@id='caller_enrollment_form:enrollmentParticipantSelectionTable:" + index + ":personSelection‌​']");


If you specifically need to identify by the text "111", you can use something like this:

var checkBox = page.FindChildByXPath("//tr[td/span[.='111']]/td/input");
checkBox.ClickChecked(true); // Check the checkbox

You can also use a variable instead of "111":

var checkBox = page.FindChildByXPath("//tr[td/span[.='" + text + "']]/td/input");

XPath explanation:

//tr                   - find a table row
    [                  - that matches this condition:
      td/span[.='111'] - any of the row's cells contains a SPAN with the text '111'
    ]
                       - then in this row
 /td/input             - find an INPUT in any cell
Helen
  • 87,344
  • 17
  • 243
  • 314
  • Thanks Helen... I wish I could use the first answer but the number 0 in the Id keeps changing ... It's the row number.. Is there a way I could append row index in th I'd field- something like 'caller...'+RowIndex+':personSelection'?? I will try the second option and see. Appreciate ur help – test Jun 16 '15 at 14:40
  • I tried the second option as well. Here also for every run my span text changes it will be 112 next time. So how will I insert dynamic values inside the FindChildByXPath function? – test Jun 16 '15 at 15:49
  • 1
    Thanks Helen ..I got it to work with: FindChildByXPath("//tr[td/span[.='"+CIN+"']]/td/input"); Can you explain what it does? – test Jun 16 '15 at 15:58
  • @test: Glad to help! I added the XPath explanation to the answer. – Helen Jun 16 '15 at 16:11
  • Thanks a lot for the great explanation!! – test Jun 16 '15 at 18:37