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?
Your problem is that element.getAttribute() is returning a Promise. You want to do something like:
element.all(by.css('a')).each(function (element) {
var linkTarget = element.getAttribute('href').then(function(attr) {;
expect(typeof attr).toBe("string");
});
});
Thanks!
Thanks!
Thanks!
thanks
+1
Thanks!
thanks!
thanks!
+1
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
// You wrote your first test, cross it off the list
todoList.get(2).element(by.css('input')).click();
var completedAmount = element.all(by.css('.done-true'));
expect(completedAmount.count()).toEqual(2);
instead of the following?
// You wrote your first test, cross it off the list
todoList.get(2).element(by.css('input')).click().then(function() {
var completedAmount = element.all(by.css('.done-true'));
expect(completedAmount.count()).toEqual(2);
});
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?
Thats explain a lot of things, Thanks
Hello!
I can not take value form place holder. I do not why.
input class="form-control ng-pristine ng-valid ng-not-empty ng-touched" type="text" ng-disabled="!conn.active" ng-model="conn.connection_name" placeholder="Connection Name"/>
Yes input does not have text value. But i can see value "new Connection" on page.
Hello. Try element.getText().then (function (data) { ....});
hello! I found solution. Uses element(...).getAttribute('value').then(function(value){
....
})
Hello all I want to print the value of textbox in a console. Here is my code
$('#ProFName').getText().then(function(text){
console.log(text);
});
How I can use getAttribute('value ')
Compare the values to two elements...
driver.findElement(By.id('input1')).getAttribute('value').then(function(a) {
driver.findElement(By.id('input2')).getAttribute('value').then(function(b) {
expect(a).to.equal(b);
});
});
Anyone know a better way to do this?
i have two input fields those are not containing any id, how to get second value from input tag, i tried it in this way,
element.all(by.css('app-root app-apitest input')).then(x => {
return x[1].getAttribute('value');
})
how can i get it?
Thank you @juliemr and @geppy, it helped a lot!.
Most helpful comment
Your problem is that element.getAttribute() is returning a Promise. You want to do something like: