2016-06-29 23 views
4

我想存儲在我的塊中的局部變量browser.executeScript的值,但我不能這樣做在所有情況下它顯示爲空。量角器 - 如何將browser.execute腳本的值存儲在varriable中?

我已經嘗試了很多方法至今

 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(); 


     }); 

真的會appreaciate也有人能告訴我如何正確地做到這一點?

回答

9

你必須在腳本中return

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

請注意,您還可以通過解決的getCssValue()同樣的問題:

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