admin管理员组文章数量:1356949
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);
});
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 am using this inside my spec as
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?
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);
});
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 am using this inside my spec as
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?
Share Improve this question edited Mar 21, 2023 at 23:31 pizzaisdavid 4693 silver badges14 bronze badges asked Jun 29, 2016 at 13:19 SandyRocksSandyRocks 2975 silver badges15 bronze badges1 Answer
Reset to default 9You need to have a return
from the script:
function returnColor()
{
return browser.executeScript('return $("#txtName").css("border-left-color");');
}
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);
});
本文标签: javascriptProtractorHow to store the value of browserexecuteScript in variableStack Overflow
版权声明:本文标题:javascript - Protractor - How to store the value of browser.executeScript in variable? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744041995a2580831.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论