js.executeScript(" arguments [0] .click();",element);

时间:2016-05-12 06:55:57

标签: html selenium xpath selenium-webdriver automation



<li class="tree-node">
    <div id="WLOBJ_mmuX_left_row_0e6d" class="default-row, no-border-row" style="height:22px">
        <table class="default-row, no-border-row" cellspacing="0" cellpadding="0" border="0" style="width:100%;height:22;">
            <tbody>
                    <tr>
                    <td class="gridcell " align="center" style="width:25;">
                        <input id="WLOBJ_mmuX_rowchk" type="hidden" value="N" style="width:10px" name="WLOBJ_mmuX_rowchk"/>
                        <input id="chk_WLOBJ_mmuX_rowchk" class="chk" type="checkbox" onclick="GRID_CORE.setcheckboxvalue(RSYS_GRID_CACHE.get('WLOBJ_mmuX'), this);(RSYS_GRID_CACHE.get('WLOBJ_mmuX').selectrow(this));" style="text-align:center" name="chk_WLOBJ_mmuX_rowchk"/>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</li>

<li class="tree-node">
    <div id="WLOBJ_mmuX_left_row_1K85" class="default-row, no-border-row" style="height:22px">
        <table class="default-row, no-border-row" cellspacing="0" cellpadding="0" border="0" style="width:100%;height:22;">
            <tbody>
                <tr>
                    <td class="gridcell " align="center" style="width:25;">
                        <input id="WLOBJ_mmuX_rowchk" type="hidden" value="N" style="width:10px" name="WLOBJ_mmuX_rowchk"/>
                        <input id="chk_WLOBJ_mmuX_rowchk" class="chk" type="checkbox" onclick="GRID_CORE.setcheckboxvalue(RSYS_GRID_CACHE.get('WLOBJ_mmuX'), this);(RSYS_GRID_CACHE.get('WLOBJ_mmuX').selectrow(this));" style="text-align:center" name="chk_WLOBJ_mmuX_rowchk"/>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</li>
&#13;
&#13;
&#13;

WebElement element= driver.findElement(By.xpath(".//div[@id='WLOBJ_mmuX_left_row_0e6d']/table[@class='default-row, no-border-row']/tbody/tr/td[@class='gridcell ']/input[@id='chk_WLOBJ_mmuX_rowchk']"));
js.executeScript("arguments[0].click();", element);

无效

1 个答案:

答案 0 :(得分:0)

从Xpath中删除类属性。 请尝试以下方法:

  

WebElement element =   driver.findElement(By.xpath( “.// DIV [@ ID = 'WLOBJ_mmuX_left_row_0e6d'] /表/ tbody的/ TR / TD /输入[2]”));

为什么需要使用

  

js.executeScript(“arguments [0] .click();”,element);

你可以使用

  

element.click();

Selenium无法识别@ class =“abc,def”属性中的“,”。让我知道这是否有助于您解决问题。