量角器定位器问题

Protractor locator issues

我的目标是拉动特定元素的 css width

我在 Chrome 控制台中使用的实际 jQuery 命令运行良好:

$('div-grid-directive[grid-name="SAT"] .qMinus1_resize_expand').first().css('width');
"0px"

但是,运行 量角器在 Win 7 cmd 提示符下,出现以下错误:

Message:
  Failed: element(...).first is not a function

错误指向我的对象页面 topNav.icons.page.js,在 this.getQMinus1Column 中:

module.exports = function(){        
    this.clickExpandRowsIcon = function(){
        $('.resize-btns > .glyphicon.glyphicon-resize-horizontal').click();
        browser.driver.sleep(2000);
    };
    this.getQMinus1Column = function(){            
        return element(by.css('div-grid-directive[grid-name="SAT"] .qMinus1_resize_expand')).first();
    };
};

和我的 SAT.spec.js 文件:

var IndexPage = require('./pageObjects/index.page.js');
var TopNavBar = require('./pageObjects/topNav.icons.page.js');

describe('Testing the Sales & Trading Top Nav grid icons', function(){
    var indexPage = new IndexPage();
    var topNavBar = new TopNavBar();
    
    beforeEach(function () {
        indexPage.get();   // Launches app !!        
    });
    describe('Clicking on the Expand Rows icon', function () {
  
        it('Should horizontally expand previous quarters qMinus1 thru qMinus6', function () {        
            topNavBar.clickExpandRowsIcon();
            var elem = topNavBar.getQMinus1Column();

            expect(elem).getCssValue().indexOf('width: 5px;').not.toBe('-1');            
  });
    });
    
});

所以在我尝试获取 css width 属性之前,我正在努力 return first(),使用这种格式:

return element(by.css('MY-CSS')).first();

我在这一行中发生的事情太多了,还是 Protractor 的语法错误?

 return element(by.css('div-grid-directive[grid-name="SAT"] .qMinus1_resize_expand')).first();

同样,在控制台工具中使用 jQuery 也可以使用相同的语法,因此 CSS select 是正确的。

非常感谢您的建议...

问候, 鲍勃

根据 thiselement 没有 return 对象集合来调用其中的 first 方法。

您可能想要使用 element.all(locator)