In a protractor end to end test, I want to check if an element exist using element(by.css(...)), my code:
var myElement = element(by.css(\'.elementClass\'));
Truthy and falsie refer to values that are evaluated to true and false after being coerced to a boolean unless you want your function to return different types of values.
var myElement = element(by.css('.elementClass'));
myElement.isPresent().then(function (elm)
{
if (elm)
{
console.log("... Element was found")
expect(myElement.getText()).toBeUndefined();
} else {
console.log("... Element was not found")
}
});
You need to test if the element is not present:
expect(element(by.css('.elementClass')).isPresent()).toBe(false);
You can test whether the element is present with isPresent. Here are the protractor docs for the isPresent function.
So, your code would be something like:
var myElement = element(by.css('.elementClass'));
expect(myElement.isPresent()).toBeFalsy();