Protractor. How to save browser.execute script value in varriable?

I am trying to store the value of browser.executeScript inside a local variable in my block, but I cannot do this in all cases when it displays zero.

I have tried many ways so far

     browser.executeScript('$("#txtName").css("border-left-color");').then(function (color) {
        console.log("This is color" + color);
    });

Also this

function returnColor()
{
     var  a = browser.executeScript('$("#txtName").css("border-left-color");');
     return a;
}

function getColorCode()
{
       var a = returnColor().then(function(list){
           console.log("Output is ***************" + list);
             return list;
      });

        return a;
}

I use this inside my specification as

   iit('', function() {        

             browser.executeScript('$("#txtName").css("border-left-color");').then(function (color) {
                console.log("This is color" + color);
            });

            returnColor();


        });

Will it really be receptive, can someone tell me how to do it right?

+4
source share
1 answer

You need to have returnfrom a script:

function returnColor()
{
    return browser.executeScript('return $("#txtName").css("border-left-color");');
}

Please note that you can also solve the same problem with getCssValue():

var elm = element(by.id("txtName"));
elm.getCssValue("border-left-color").then(function (color) {
    console.log(color);
});
+9
source

All Articles