我正在使用 Selenium 记录 Web 应用程序的测试脚本。
应用程序中的某些页面包含表示数据库中记录列表的表。有一个 jquery click 处理程序附加到表行,它加载一个页面,允许用户在单击表行时编辑相关记录。
不幸的是,Selenium IDE 不会记录对表行的点击。我看过代码,相关函数是:
Recorder.prototype.findClickableElement = function(e) {
if (!e.tagName) return null;
var tagName = e.tagName.toLowerCase();
var type = e.type;
if (e.hasAttribute("onclick") || e.hasAttribute("href") || tagName == "button" ||
(tagName == "input" &&
(type == "submit" || type == "button" || type == "image" || type == "radio" || type == "checkbox" || type == "reset"))) {
return e;
} else {
if (e.parentNode != null) {
return this.findClickableElement(e.parentNode);
} else {
return null;
}
}
}
我试图通过添加以下内容来修改它:
if($ && $._data) {
var ev = $._data(e, "events");
if(ev && ev.click)
return e;
}
但是, $._data 为空!
如果我在 Firebug 中查看相同的变量,打开相同的网页,$._data 存在,并且 $._data(e, "events").click 也存在。
我不确定为什么它存在于 Firebug 中,但不存在于 Selenium 中。Selenium 是否有可能在不同的上下文中运行,所以有 2 个不同的“$”变量,还是什么?