2016-03-08 28 views
0

下面是html代碼...我想知道哪個xpath可以用來選擇這樣一個複選框。需要xpath用於選擇硒web驅動程序中的複選框

在實際的HTML代碼中,我有多個td複選框,在這裏我只顯示了一個。

我已經嘗試過

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

,但它給出了一個錯誤說網頁上找到沒有這樣的元素。

<table id="cntMain_GridView1" class="table iconTwo" cellspacing="0" cellpadding="3" style="width:100%;border-collapse:collapse;"> 
    <tbody> 
    <tr> 
     <td class="no-sorting" valign="top" align="left" style="width:10px;"> 
     <p class="defaultP" tabindex="35"> 
      <span style="display:inline-block;width:5%;"> 
      <div class="ez-checkbox"> 
       <div class="ez-checkbox"> 
       <input id="cntMain_GridView1_chIndividual_0" class="ez-hide" type="checkbox" onclick="javascript:RbtnOnOff(this.id);" name="ctl00$cntMain$GridView1$ctl02$chIndividual" tabindex="-1"/> 
       </div> 
      </div> 
      </span> 
     </p> 
     </td> 
    </tr> 
    </tbody> 
</table> 
+0

「frame」中的複選框? – JRodDynamite

+0

不,沒有框架或窗口 –

回答

0

嘗試更改元素的display樣式屬性,然後單擊該元素。使用JavascriptExecutor使元素可見。試試以下代碼:

JavascriptExecutor js = (JavascriptExecutor) driver; 
String domain_name = (String) js.executeScript("return document.getElementById(" + 
      "'cntMain_GridView1_chIndividual_0').style.visibility = 'visible'"); 

driver.findElement(By.id("cntMain_GridView1_chIndividual_0")).click(); 
+0

非常感謝你現在爲我工作得很好 –

相關問題