I have also checked link: Protractor: element.getText() returns an object and not String but i found no answer for that on above link and i want string in return??
1 Answer
All the protractor's methods return promises, to resolve that promise you need to send something like this:
element.getText().then(function(text) {
console.log(text);
});
or use "expect"-->jasmine's assertion
expect(element.getText()).toEqual("Your Text");
for detailed idea on promises i suggest please go through this link : http://www.html5rocks.com/en/tutorials/es6/promises/
8 Comments
Saurabh
I have tried : var abc= element(by.xpath("//h1[@ng-model='Save Employee']")); abc.getText().then(function(value) {console.log(value);}); //output- undefined but i want text instead of object or undefined
Ram Pasala
ok try this element(by.xpath("//h1[@ng-model='Save Employee']")).getText().then(function(text)){ console.log(text)}); if it doesn't work your xpath has a problem.
Ram Pasala
Xpath slow down the dom's rendering process, which in turn slow your scripts, xpaths should always be the last option, please use cssSelectors or the built in protractor locators instead. var abc = element(by.model('Save Employee'));
emory
@Saurabh promises can take 2 arguments: a success and and error callback. try
element(by.xpath("//h1[@ng-model='Save Employee']")); abc.getText().then(function(success) {console.log("SUCCESS: "+success);}, function(error){console.log("ERROR: "+error);}); I am guessing that your xpath has a problem and the error function will help you identify it.Ram Pasala
@Saurabh please check gitter, i have posted my answer and also please check this link for asking questions in StackOverflow : stackoverflow.com/help/someone-answers
|