和 CSS 選擇器定位器快捷方式

Protractor API 允許 CSS 元素定位器使用類似 jQuery 的快捷方式符號 $()

普通的 CSS 元素定位器

element(by.css('h1.documentation-text[ng-bind="title"]'));
element(by.css('[ng-click="submit"]));

快捷方式 $() CSS 元素定位器

$('h1.documentation-text[ng-bind="title"]');
$('[ng-click="submit"]');

要在定位器下查詢多個元素,請使用快捷方式 $$()

普通的 CSS 元素定位器

element.all(by.css('h1.documentation-text[ng-bind="title"]'));
element.all(by.css('[ng-click="submit"]));

快捷方式 $$() CSS 元素定位器

$$('h1.documentation-text[ng-bind="title"]');
$$('[ng-click="submit"]');