Use element by css to check if element exists in Protractor

前端 未结 3 756
一个人的身影
一个人的身影 2020-12-16 09:17

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\'));         


        
3条回答
  •  生来不讨喜
    2020-12-16 09:35

    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")
        }
    });
    

提交回复
热议问题