問(wèn)題描述
我不太明白 $ 和 $$ 命令的用途.我認(rèn)為它們只是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>
我認(rèn)為,鑒于上述情況,這些將是等效的:
I thought, that given the above, these would be equivalent:
element(by.css('#eId'));
和
element($('#eId'));
但是,第一個(gè)有效,第二個(gè)無(wú)效.為什么,這三者有什么區(qū)別?
However, the first one works and the second doesn't. Why, what's the difference between the three?
docs 幫助不大.他們似乎暗示$"僅用于鏈接,例如element(by.css('#eId')).element($('#childId'));
或選擇第一個(gè)元素,然后選擇第一個(gè)元素內(nèi)的第二個(gè)元素."但是,我已經(jīng)看到使用 $ 來(lái)選擇第一個(gè)元素的示例.
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.
不管怎樣,這三個(gè)(by.css、$ 和 $$)之間有什么區(qū)別?"的文字很多.
Anyway, that's a lot of text for "What are the differences between the three (by.css, $, and $$)?"
推薦答案
$
和 $$
只是方便的快捷方式.
$
and $$
are just convenient shortcuts.
$("selector")
是 element(by.css("selector"))
的替代品.
$$("selector")
是 element.all(by.css("selector"))
的替代品.
僅供參考,引用自 源代碼:p>
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));
};
以及最初實(shí)現(xiàn)它的實(shí)際提交.
這篇關(guān)于量角器“by.css()"vs“$()"美元符號(hào)與“$$()"'亮閃閃'的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!