Pages

How to clear text in text field ?

How to clear text in text field ?

>> In protractor, we can clear the value in textbox using clear().

>> clear() will not return any value.

Please check below code script:

First write xpath with help of DOM


clear() in protractor
clear() in protractor


describe('Protractor - clear()', function () {
it('Code script to use clear() in protractor', function () {
browser.get("https://keeplearners.blogspot.com/2018/03/Angular-elements.html");
var textElement = element(by.model('name'));
enterText(textElement, "Keeplearners");
clearTextBox(textElement);
});

function enterText(element, text) {
element.sendKeys(text).then(function () {
console.log("Entered " + text + " in text box");
});
}

function clearTextBox(element) {
element.clear().then(function () {
console.log("Cleared text in text box")
});
}
});
Here we have written xpath using Angular locator by.model.
sendKeys() will take string as an argument to enter text into text box.
clear() will clear value in text box.
Output:
clear() in protractor
clear() in protractor
Please comment below to feedback or ask questions.

No comments:

Post a Comment

Please comment below to feedback or ask questions.