Reputation: 11794
Starting to learn more about protractor. Question: how do I check whether an element exists on a page? The first property firstNsame does not exist. I would like to move on with the rest of the script if an element does not exist. I am using this script but looks like the isPresent() code does not work:
var data = {"firstNsame": "Joke", "lastName": "Moker", "stateId": 49};
for (var key in data) {
try {
if (data.hasOwnProperty(key)) {
var el = element(by.model(key));
if (el.isPresent())
{
console.log('element present',key);
}
else
{
console.log('element not present',key);
}
}
}
catch (err) {
console.log('error occured',err);
}
}
Upvotes: 1
Views: 153
Reputation: 8900
Try the following:
element(by.model(key)).isPresent().then(function(present) {
console.log('Element present', present)
});
Upvotes: 1