Protractor “by.css()” vs “$()” Dollar Sign vs “$$()” 'Bling Bling'

十年热恋 提交于 2019-12-18 13:55:08

问题


I don't really understand what the $ and $$ commands are for. I thought they are just a replacement for 'by.css' but why the $$?

<element id = "eId"></element>

I thought, that given the above, these would be equivalent:

element(by.css('#eId'));

and

element($('#eId'));

However, the first one works and the second doesn't. Why, what's the difference between the three?

The docs are of little help. They seem to imply that "$" is for chaining only, e.g. element(by.css('#eId')).element($('#childId')); or "Select the first element, and then select the second element within the first element.' However, I have seen examples with $ being used to select the first element.

Anyway, that's a lot of text for "What are the differences between the three (by.css, $, and $$)?"


回答1:


$ and $$ are just convenient shortcuts.

$("selector") is an alternative for element(by.css("selector")).

$$("selector") is an alternative for element.all(by.css("selector")).


FYI, quote from the source code:

ElementFinder.prototype.$ = function(selector) {
  return this.element(webdriver.By.css(selector));
};

ElementArrayFinder.prototype.$$ = function(selector) {
  return this.all(webdriver.By.css(selector));
};

And the actual commit that initially made it happen.



来源:https://stackoverflow.com/questions/31881583/protractor-by-css-vs-dollar-sign-vs-bling-bling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!