我使用Selenium IDE在我的自定义函数文件中调用jQuery库(Selenium使用我相信的原型),之前没有遇到过问题,但最近对Firefox的更新似乎引起了一个问题。我发现了这个问题,它源于这个功能
/* allow use of jQuerys global variable $ */
function _getGlobalVar(varName) {
var win = selenium.browserbot.getUserWindow();
if (win[varName]) {
return win[varName];
} else {
throw undefined;
}
}
/* allows use of Jquery selectors in pages where jQuery is loaded*/
function jQuery(selector) {
var jq = _getGlobalVar('jQuery');
if (typeof jq != 'undefined') {
return jq(selector);
} else {
throw new SeleniumError('jQuery is not defined in the current window');
}
}
当我想在以下函数中使用jQuerys trim方法时。我已经阅读了文档,我知道我可以使用jQuery.noConflict();
,但它似乎没有帮助
Selenium.prototype.doClickSearchTemplate = function (locator, action) {
$ = _getGlobalVar('jQuery');
profileToggleButton = null;
profileName = '';
var locator = locator || 'id=content';
var reportBlockContainer = this.page().findElement(locator);
jQuery(reportBlockContainer).find('.reportBlockHeader h2 strong').each(function(index, elem) {
profileName = $.trim(jQuery(elem).text());
if (profileName == action)
profileToggleButton = elem.parentNode.previousElementSibling; // previousSibling = jQuery(elem).parent().prev().get(0);
});
if (profileToggleButton === null)
throw new SeleniumError("Invalid Search Template Name: " +action);
this.browserbot.clickElement(profileToggleButton);
};
这导致的问题是,当我点击“播放当前的测试用例'第一次运行正常,调用此功能,执行功能,我的测试将通过,但是当我尝试按“播放当前测试用例”时再次,它就像按钮被禁用,它不会被激活。
如果我没有调用此功能,那么一切正常,我不确定它是否与$
变量的分配有关。
答案 0 :(得分:0)
通过回到JavaScript来解决这个问题
profileName = jQuery(elem).text();
profileName = profileName.trim();
现在一切都很好