量角器 - 如何将 browser.executeScript 的值存储在变量中? [英] Protractor - How to store the value of browser.executeScript in variable?

查看:38
本文介绍了量角器 - 如何将 browser.executeScript 的值存储在变量中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将 browser.executeScript 的值存储在我的 it 块中的局部变量中,但我无法在它显示为空的所有情况下都这样做.

I am trying to store the value of browser.executeScript inside a local variable in my it block but I am not able to do so in all the cases it displays null.

到目前为止我已经尝试了很多方法

I have tried many ways so far

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

还有这个

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

我在我的规范中使用它

   iit('', function() {        

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

            returnColor();


        });

真的有人能告诉我如何正确地做吗?

Will really appreaciate it someone can tell me how to do it properly?

推荐答案

您需要从脚本中获得 return :

You need to have a return from the script:

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

请注意,您也可以通过getCssValue():

Note that you can also solve the same problem via getCssValue():

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

这篇关于量角器 - 如何将 browser.executeScript 的值存储在变量中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆