量角器,按css计数不起作用

时间:2016-11-09 07:57:11

标签: css protractor

在页面中有这样的列:

<span translate="" class="ng-scope ng-binding">Number of Products</span>

<span translate="" class="ng-scope ng-binding">Number of Processed Products</span>

number of preprocessed Products
number of Products

因此,要检查页面是否存在,我会尝试检查这些列是否处于活动状态。

所以,我这样做:

        var el =  element.all(by.css( "Products</span>"));
        var EC = protractor.ExpectedConditions;
        browser.wait(EC.presenceOf(el), 5000);

但错误是

Message:
    Failed: Cannot read property 'bind' of undefined
  Stack:
    TypeError: Cannot read property 'bind' of undefined
        at ProtractorExpectedConditions.presenceOf (/usr/lib/node_modules/protractor/built/expectedConditions.js:354:39)

所以我改成了这个

                    var EC = protractor.ExpectedConditions;
                 //   browser.wait(EC.presenceOf(el), 1000);
                      browser.wait(EC.visibilityOf(element(by.
cssContainingText('span', 'Products'))), 5000);  // maximum wait of 5 seconds

                    expect((element(by.cssContainingText('span', 'Products'))).count()).toEqual(1);

但错误是

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

当我这样做时

 var el = element(by.cssContainingText('span', 'Products'));
                var EC = protractor.ExpectedConditions;
                browser.wait(EC.presenceOf(el), 5000);  // maximum wait of 5 seconds
                expect(el.count()).toEqual(1);

错误

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








  var el =  element.all(by.css( "Products"));
        var EC = protractor.ExpectedConditions;
        browser.wait(EC.visibilityOf(el), 1000);


        expect(el.count()).toEqual(1);

此错误

 Failed: Cannot read property 'bind' of undefined

对于''或“”

是相同的

2 个答案:

答案 0 :(得分:1)

基本上您使用的定位器无效,count方法仅适用于element.all()$$()方法。请尝试以下代码,

var el = element.all(by.cssContainingText('span', 'Products'));
var EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(el), 5000);  
expect(el.count()).toEqual(1);

答案 1 :(得分:0)

   var EC = protractor.ExpectedConditions;
                 //   browser.wait(EC.presenceOf(el), 1000);
                      browser.wait(EC.visibilityOf(element(by.
cssContainingText('span', 'Products'))), 5000);  // maximum wait of 5 seconds

                    expect((element.all(by.cssContainingText('span', 'Products'))).count()).toEqual(1);