量角器“by.css()” vs" $()"美元符号vs“$$()” '亮闪闪' [英] Protractor "by.css()" vs "$()" Dollar Sign vs "$$()" 'Bling Bling'
问题描述
我真的不明白$和$$命令的用途。我认为它们只是'by.css'的替代品,但为什么是$$?
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'));
和
element($('#eId'));
然而,第一个有效,第二个无效。为什么,三者之间有什么区别?
However, the first one works and the second doesn't. Why, what's the difference between the three?
docs 没什么帮助。他们似乎暗示$仅用于链接,例如元素(by.css('#eId'))。element($('#childId'));
或选择第一个元素,然后选择第二个元素在第一个元素中。'但是,我已经看到了使用$来选择第一个元素的例子。
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.
无论如何,这是有什么区别的文本三者之间(by.css,$和$$)?
Anyway, that's a lot of text for "What are the differences between the three (by.css, $, and $$)?"
推荐答案
$
and $$
are just convenient shortcuts.
$(selector)
是元素的替代方案(by.css(selector))
。
$$(selector)
是元素的替代方法。(by.css(selector))
。
仅供参考,引自源代码:
ElementFinder.prototype.$ = function(selector) {
return this.element(webdriver.By.css(selector));
};
ElementArrayFinder.prototype.$$ = function(selector) {
return this.all(webdriver.By.css(selector));
};
实际提交。
这篇关于量角器“by.css()” vs" $()"美元符号vs“$$()” '亮闪闪'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!