首页 > 解决方案 > 点击事件未在 GWT 网站上触发

问题描述

我正在尝试在 GWT 构建站点的客户端自动化测试。我已经能够遍历所有 DOM 元素并找到可点击的 span 元素我尝试了 click() 方法,但它永远不会触发。

这只能在客户端完成。我无法调整源代码以包含任何 ID 或名称。

这是我的草稿本中的 HTML 代码。这确实找到了包含表格的 div 并获得了第一个 td 内的 span 标签。

    <div tabindex="1779" id="isc_8C" style="left: 0px; top: 62px; width: 1566px; height: 165px; overflow: hidden; display: inline-block; position: absolute; z-index: 201998; cursor: default; background-color: white;" onfocus="isc.EH.focusInCanvas(ResultsGrid_1_body,true);"
onblur="if(window.isc)isc.EH.blurFocusCanvas(ResultsGrid_1_body,true);" onscroll="return ResultsGrid_1_body.$lh()" eventproxy="ResultsGrid_1_body">
    <div id="isc_8B" style="width: 1566px; position: relative; z-index: 1000;">
        <form onsubmit="return false;" action="javascript:void(0)">
            <div id="ResultsGrid_1_body$28s" style="width: 1px; height: 0px; overflow: hidden; display: none;"><span style='width: 1px; height: 0px; vertical-align: text-top; display: inline-block;'></span>
            </div>
            <table width="1550" class="listTable" id="isc_8Ctable" role="presentation" style="overflow: hidden; table-layout: fixed;" border="0" cellspacing="0" cellpadding="2">
                <tbody>
                    <tr role="listitem" aria-selected="true" aria-posinset="1" aria-setsize="1">
                        <td width="396" align="left" class="tallCellSelectedOver" style="height: 16px; overflow: hidden;">
                            <span class="clickable">748754434564</span>
                        </td>
                        <td width="180" align="left" class="tallCellSelectedOver" style="height: 16px; overflow: hidden;">Jon, smith</td>
                </tbody>
            </table>
            <div id="ResultsGrid_1_body$284" style="width: 1px; height: 0px; overflow: hidden; display: none;"><span style='width: 1px; height: 0px; vertical-align: text-top; display: inline-block;'></span>
            </div>
        </form>
    </div>
</div>

脚本代码是

$('div [eventproxy=ResultsGrid_1_body] table td span').click();

如何单击 span 标签?

标签: javascriptjqueryhtmlgwtautomation

解决方案


尝试将 id 与 span 相关联,然后在 body 标记的末尾添加函数,或者如果包含 js 文件,则在 body 标记上方调用它,而不是在开头。

<span id="sp"> </span>

工作示例可以在这里看到

https://jsfiddle.net/2b645Lup/5/


推荐阅读