繁体   English   中英

jQuery与原型硒没有冲突

[英]jQuery no conflict with prototype Selenium

我正在使用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);
};

导致的问题是,当我单击“播放当前测试用例”时,它将第一次正常运行,调用此函数,执行该功能,我的测试将通过,但是当我尝试再次按“播放当前测试用例”时,就好像该按钮已被禁用并且不会触发。

如果我不调用此函数,那么一切正常,我不确定它是否与$变量的分配有关。

通过重新使用JavaScript解决了此问题

profileName = jQuery(elem).text();
profileName = profileName.trim();

现在一切都很好

暂无
暂无

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

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