简体   繁体   English

GWT网站上的模拟点击未触发事件

[英]Simulated Click not firing event on GWT site

I am attempting to automate testing on the client side of a GWT built site with VAADIN as a framework. 我正在尝试使用VAADIN作为框架在GWT构建站点的客户端上进行自动化测试。

I have been able to run through the all the DOM elements and find the one div that contains the " button ". 我已经能够遍历所有DOM元素并找到包含“ button ”的一个div。 (It not a button, just text styled to look like a button.) I tried the click() method but it never fires. (它不是按钮,只是样式看起来像按钮的文本。)我尝试了click()方法,但从未触发。

This can only be done on the client-side. 这只能在客户端完成。 I cannot adjust the source code to contain any ID's or names. 我无法调整源代码以包含任何ID或名称。 I only have the method for locating the button. 我只有定位按钮的方法。

Here is my Javascript code from the scratch pad. 这是我从头开始的Javascript代码。 This does find the div that contains the " button ". 这确实找到了包含“ 按钮 ”的div。

var bDivClass = "v-rasterlayout-slot";
var divs = document.getElementsByClassName(bDivClass);

for (var i = 0, len = divs.length; i < len; i++) {
     divs[i].click();
    if(divs[i].textContent.localeCompare("Submit Query") == 0){
        console.log("Submit Button found \n" + divs[i].innerHTML);
        divs[i].click();
    }
}

OUTPUTS: 输出: 在此处输入图片说明

If I inspect the element, I can see a couple of the DIVs have click listeners attached. 如果检查该元素,则可以看到几个DIV附加了单击侦听器。

在此处输入图片说明

Here is the event listener. 这是事件监听器。 It is the same for both the child and the parent. 对于孩子和父母来说都是一样的。

在此处输入图片说明

How do I simulate a click on that div? 如何模拟对该div的点击?

In your case getElementsByClassName() returns only one top-level-in-that-context element which has no event listeners attached. 在您的情况下, getElementsByClassName()仅返回一个上下文关联的顶级元素,该元素未附加事件侦听器。 If you want to simulate a click on every child of that element you need to iterate over childs . 如果要模拟在您需要遍历孩子的该元素的每个孩子一个点击。 Your loop actually doesn't do that. 您的循环实际上不这样做。

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

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