protractor: element ... .getAttribute(...) returning Objects unexpectedly
I’m collecting all of the anchor tags on a page with the intent of checking to ensure that they aren’t dead links… but I’m unexpectedly finding that I’m unable to get valid HREF values for half of them.
element.all(by.css('a')).each(function (element) {
var linkTarget = element.getAttribute('href');
expect(typeof linkTarget).toBe("string");
});
If I run code in the browser on the same site, I find that all of my anchor tags have an href of type “string”. Am I using the API incorrectly? I’m using Protractor on a non-Angular page: does this functionality depend on Angular?
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 19 (1 by maintainers)
Your problem is that element.getAttribute() is returning a Promise. You want to do something like:
Since pretty much everything in Protractor returns a promise I was wondering when is required to
then
and when it is not.As per this excerpt from the web page, why is this OK
instead of the following?
Do I have any guarantee that what is triggered by the click has finished executing by the time the rest of the code is executed?
Compare the values to two elements…
Anyone know a better way to do this?