Protractor Locators

All functions return promises.

Get full text from a css list which containing word “keyword”:

var requiredText = ''

element.all(by.cssContainingText('.uniqueClassName', 'keyword')).get(0).getText().then(function (text) {
console.log(text);
requiredText = text
});

Below are quoted partially and edited from luxiyalu

$('#some-id')                // element(by.id())
$('.some-class')             // element(by.className())
$('tag-name')               // element(by.tagName())
$('[ng-message=required]')   // remember to leave out the double quotes around the value of attribute
$('#parent #child')          // select one child inside parent
$('ul li')                   // select all children inside parent
$('ul li').first()           // select first of children
$('ul li').last()            // select last of children
$('ul li').get(index)        // select index-th of children
$($('.classname')[0]).text()       //get the element text of first class list
$($('.classname')[0]).trigger('click')  // click the first item in the list

element(by.model('data'));
element(by.repeater('cat in pets'));
element(by.options('c for c in colors'))
element(by.binding('value'));           // only look through the elements with ng-binding attribute
element(by.buttonText('Save'));         // the whole of button text
element(by.partialButtonText('Save'));  // part of button text
element(by.cssContainingText('.pet', 'Dog')) // for selecting this: <li class="pet">Dog</li>
element(by.deepCss('span'))             // for selecting all level of spans <span><span>x</span></span>

element(by.css('dr.ng-scope > td.name > div > a')).click() // click the child element
element(by.xpath("//a[@href-raw='"+keywd+"']/../../..//input[contains(@type, 'checkbox')]")).click
               // click the nested element by the sibling element.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s