element ... .getAttribute(...) returning Objects unexpectedly
See original GitHub issueI’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?
Issue Analytics
- State:
- Created 9 years ago
- Comments:19 (1 by maintainers)
Top Results From Across the Web
Javascript: getAttribute throwing unexpected identifier when ...
Try doing that in connectedCallback() function. Info: constructor() is called when the element is created.
Read more >Element.getAttribute() - Web APIs | MDN
The getAttribute() method of the Element interface returns the value of a specified attribute on the element.
Read more >what does Object GetAttributeValue( string name ) return?
No, by randomly I mean that the error sometimes occurs and sometimes not. However, when it occurs, it occurs for the same attribute...
Read more >Attributes and properties - The Modern JavaScript Tutorial
The attributes collection is iterable and has all the attributes of the element (standard and non-standard) as objects with name and value ...
Read more >Can't get value from field - Katalon Community
When I try to get the text from this field, it returns nothing. ... getAttribute(findTestObject('Object Id'), 'value') println result.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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?