Testcomplete使用Xpath单击Checkbox

时间:2015-06-15 21:35:23

标签: html xpath testcomplete

我确实有以下HTML文字:

<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>

我试图点击同一行中包含数据111的复选框。

我正在尝试这样的事情:

  

page.FindChildByXPath(“//跨度[含有(文本(), '111')] /父:: TD /前同辈:: TD /输入[@名称= 'caller_enrollment_form:enrollmentParticipantSelectionTable:0:personSelection' ]”,假)

但是我找不到对象错误。

1 个答案:

答案 0 :(得分:0)

您的checkox具有ID,并且ID在页面中是唯一的。所以你可以使用:

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

ID包含数字(0);您可以使用变量来指定此数字:

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


如果您特别需要通过文本“111”进行识别,则可以使用以下内容:

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

您也可以使用变量而不是“111”:

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

XPath解释:

//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