How to use sendKeys() in protractor ?
In protractor, we can enter text in textbox(es) using sendKeys() function.
Please check below code script:
First write xpath with help of DOM
describe('Protractor to get current page title', function () {
it('Code script to get current page title', function () {
browser.get("https://keeplearners.blogspot.com/2018/03/Angular-elements.html");
var textField = element(by.model('name'));
textField.sendKeys("Entered sample text");
});
});
Here we have written xpath using Angular locator by.model.
sendKeys() will take string as an argument to enter text into text box.
Output:
It will enter text like below:We can also write generic function for sendKeys() like below:
describe('Protractor to get current page title', function () {
it('Code script to get current page title', function () {
browser.get("https://keeplearners.blogspot.com/2018/03/Angular-elements.html");
var textField = element(by.model('name'));
enterText(textField, "Entered sample text");
});
function enterText(element, text) {
element.sendKeys(text).then(function () {
console.log("Entered " + text + " in text box");
});
}
});
Please comment below to feedback or ask questions.
This post is so helpfull and informative.keep updating with more information...
ReplyDeleteAbout Android Technology
Android Application Developers