$$ Selector in Protractor

I have seen in many examples like this $('.selector'), and I also use this. So what does this variable $ do . This is what I got from the protractor docs .

$ Calls can be chained to find elements inside the parent.

There is $no example in the documents in which it is used . We use $to chain with a selector element.

It is also $('.selector')an element in itself, when we do this element($('.selector')), it is a mistake.

So how to use the selector $in the protractor. Does it have all the features JQuery $. I tried $('.selector').children, which says it is childrennot a function.

Any help is greatly appreciated.

Thank!

+4
source share
3 answers

It looks like jQuery syntax, but it is not, it is part of Protractor. Therefore, it .childrenthrows an error, because we actually do not use jQuery. $is a shortened version of element(by.css())ie

$('my-css'); is the same as element(by.css('my-css'));

They also have $$that coincides withelement.all(by.css())

Despite the lack of documentation, you must not use bindings to search for children . those. using the “Julie” demo (I changed the example):

describe('Protractor Demo App', function() {
  it('read the header', function() {
    browser.get('http://juliemr.imtqy.com/protractor-demo/');
    $('h3').getText().then(function (val) {
      console.log(val);
    });
  });
});

h3, . $ $$ css.

: $$, $,

, ( $$: http://luxiyalu.com/protractor-locators-selectors/

+7

API- Protractor $. , Protractor , $. . ( spec/async_spec.js):

  it('should work with synchronous actions', function() {
    var increment = $('#increment');
    increment.$('.action').click();

    expect(increment.$('.val').getText()).toEqual('1');
  });
+1

API- $:

" css. element(by.css('.abc')) $('.abc')"

http://www.protractortest.org/#/api?view=build $

0
source

All Articles