Krunal Patel
Krunal Patel

Reputation: 35

Not able to click on checkbox using selenium web driver

I tried to use objectIdentifierValue

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

but none are working,I am getting errors like "No such element found on web page".

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.

How we can select such checkbox using a webdriver script?

Any help would be appreciated.

Here is the below html code :

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

Upvotes: 0

Views: 484

Answers (2)

Mayank
Mayank

Reputation: 41

Use the code:

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

Try with clicking on span which is parent of that particular input

Upvotes: 1

noor
noor

Reputation: 3004

have u tried this:

driver.findElement(By.id("cntMain_chkPrimaryInvestigator_A")).click();

if this does not help, pls show details of your code.

Upvotes: 0

Related Questions