无法使用selenium web驱动程序单击复选框

时间:2016-03-04 13:16:58

标签: selenium-webdriver

我尝试使用objectIdentifierValue

id - cntMain_chkPrimaryInvestigator_A   
name - ctl00$cntMain$chkPrimaryInvestigator_A    
xpath - //input[@id='cntMain_chkPrimaryInvestigator_A'] 
xpath - //span/div/input

但没有一个正常工作,我收到错误,例如"在网页上找不到这样的元素"。

Going through the examples given for all the other related questions I could not find a proper solution that works in a concise way that allows me to check a checkbox with a few lines of code or method.

我们如何使用webdriver脚本选择此类复选框?

任何帮助都将不胜感激。

以下是html代码:

<div class="input-heading nonresearchHide">
    <span id="cntMain_lbl_Primary_investigator">Primary investigator</span>
    </div>
    <div class="nonresearchHide">
    <div class="icon-info" data-content='Please add the Primary Investigator that was responsible for the research if they are not already added to this activity' data-placement="top" data-toggle="popover" data-container="body" data-trigger="hover"></div>
    <p class="defaultP">
    <div class="RadAjaxPanel" id="ctl00_ctl00_cntMain_chkPrimaryInvestigator_APanel">
    <span class="check_box">
    <input id="cntMain_chkPrimaryInvestigator_A" type="checkbox" name="ctl00$cntMain$chkPrimaryInvestigator_A" tabindex="7" />
    </span>
    </div>
    </p>
    </div>

2 个答案:

答案 0 :(得分:1)

使用代码:

driver.findElement(By.xpath("//span[@class='check_box]")).click();

尝试单击作为特定输入的父级的跨度

答案 1 :(得分:0)

你尝试过这个:

<TagOne>
<TagTwo>Abc</TagTwo>
<TagThree>Xyz</TagThree>
</TagOne>

如果这没有用,请显示代码的详细信息。