简体   繁体   English

需要Xpath来选择Selenium Web驱动程序中的复选框

[英]Need xpath for selecting checkbox in selenium web driver

Below is the html code... I want to know which xpath can I use to select such a check box. 以下是html代码...我想知道可以使用哪个xpath来选择这样的复选框。

In actual HTML code I have multiple td for checkboxes, here I have shown only one. 在实际的HTML代码中,我有多个td用于复选框,此处仅显示了一个。

I already tried 我已经试过了

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

but it gives an error saying no such element found on web page. 但是它给出一个错误,指出在网页上找不到这样的元素。

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

Try changing the display style property of the element and then clicking on the element. 尝试更改元素的display样式属性,然后单击该元素。 Use JavascriptExecutor to make the element visible. 使用JavascriptExecutor使该元素可见。 Try the following code: 尝试以下代码:

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM