我见过很多这样的例子 $('.selector')
并且我也在使用这个。那么这个 $ 变量的作用是什么。这是我从 Protractor 得到的docs .
Calls to $ may be chained to find elements within a parent.
文档中没有单独使用 $
的示例。我们使用 $
与 element
选择器链接。
另外$('.selector')
本身就是一个元素,当我们执行这个element($('.selector'))
时,它是一个错误。
那么如何在 Protractor 中使用这个$
选择器。它是否具有JQuery$
的所有功能。我尝试了 $('.selector').children
,它说 children
不是一个函数。
非常感谢任何帮助。
谢谢!
最佳答案
这看起来像 jQuery 语法,但事实并非如此,它是 Protractor 的一部分。这就是 .children
抛出错误的原因,因为我们实际上并没有使用 jQuery。 $
是 element(by.css())
的简写版本,即
$('my-css');
与 element(by.css('my-css'));
它们还有 $$
,与 element.all(by.css())
尽管缺乏文档,但它不必必须用于链接来查找子元素。即使用 Julie 的 Protractor 演示(我修改了示例):
describe('Protractor Demo App', function() {
it('read the header', function() {
browser.get('http://juliemr.github.io/protractor-demo/');
$('h3').getText().then(function (val) {
console.log(val);
});
});
});
这会打印出我找到的 h3 元素的标题。 $
和 $$
只是 css 选择器的简写。
来源:here for $$ , here for $ ,和here for more
这也是我发现的一个很好的文档(尽管它没有提到 $$
的使用:http://luxiyalu.com/protractor-locators-selectors/
关于angularjs - Protractor 中的“$”选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36791397/