17

Is it possible to get an element by its name like you can with jQuery? I'm trying to do the equivalent of the jQuery selector like in jQuery

$('h1')

how is this done with protractor?

I tried

element('h1')

but it doesn't work

4

2 回答 2

30

有几种方法可以做到这一点 - 您可以通过 tagName 或 css 选择器获取它。因此,以下任何一项工作:

element(by.css('h1')); // works with any css selector
$('h1'); // works with any css selector
element(by.tagName('h1'));
于 2013-12-06T02:45:16.680 回答
19

答案终于在github上找到了,他们有一个测试文件,显示了所有的选择器

element(by.css('h1'));
element(by.css('.my-class'));
于 2013-12-05T23:24:38.270 回答