2016-03-04 95 views
0

複選框,我試圖用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> 
+0

你應該增加更多的細節,比如你的代碼的母公司。 – Prateek

回答

0

具有u試過這樣:

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

如果這沒有幫助,請展示你的代碼的細節。

+0

我已經嘗試過driver.findElement(By.id(「cntMain_chkPrimaryInvestigator_A」))。click(); 我的代碼如下: element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(objectIdentifierValue))); element.click(); \t \t \t \t \t element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(objectIdentifierValue))); element.click(); \t \t \t \t \t 我試圖與以下objectIdentifierValue如\t - > ID = cntMain_chkPrimaryInvestigator_A \t \t - >名= ctl00 $ $ cntMain chkPrimaryInvestigator_A - >的xpath = //輸入[@ ID = 'cntMain_chkPrimaryInvestigator_A'] - > xpath = // span/div/input –

1

使用代碼:

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

嘗試用點擊跨度它是特定的輸入

+0

我用上面的xpath嘗試過,但它也不起作用。有一些jquery在後臺被調用。有什麼辦法來處理硒中的jquery –