07 Locators - biswajitsundara/Protractor GitHub Wiki
Protractor supports all the locators supported by selenium and some more.
- Protractor recommends to use css, id, name, model, binding primarily
- It supports other locators used in selenium too such as by tagname, xpath etc.
- Locating by xpath is discouraged by Protractor API
-
modelandbindingare two new locators which will be available only in angular pages
const { element } = require("protractor");
describe('Protractor Locator Demo', function() {
it('should have a title', function() {
browser.get('http://juliemr.github.io/protractor-demo/');
expect(browser.getTitle()).toEqual('Super Calculator');
element(by.model('first')).sendKeys('5');
element(by.model('second')).sendKeys('3');
element(by.id('gobutton')).click();
element(by.css("h2[class='ng-binding'")).getText().then((result)=>{
console.log(result);
})
});
});
Reference
https://www.protractortest.org/#/locators
http://www.protractortest.org/#/api?view=ProtractorBy