Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the syntax for selecting an element in protractor via element name

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

like image 237
Subtubes Avatar asked Dec 05 '13 16:12

Subtubes


People also ask

How do you select a specific element?

To select an HTML element using its id, we use a hash(#) symbol followed by id. In the following example, the id selector selects an element with id=“head1” and adjusts its alignment to the left while color to aqua. Class selector styles an HTML element on the basis of a specific class attribute.

How do you find the child element in a protractor?

you can use nth-child() selector to access to a child element.


2 Answers

There's a couple ways to do this - you can either get it by tagName or by css selector. So any of the following work:

element(by.css('h1')); // works with any css selector
$('h1'); // works with any css selector
element(by.tagName('h1'));
like image 157
Jmr Avatar answered Nov 16 '22 02:11

Jmr


The answer was finally found on github they have a test file that shows all the selectors

element(by.css('h1'));
element(by.css('.my-class'));
like image 45
Subtubes Avatar answered Nov 16 '22 02:11

Subtubes