簡體   English   中英

protratcor:使用executescript在元素上執行javascript的問題

[英]protratcor : Issue with using executescript to execute javascript on an element

我寫了下面的代碼來在元素上執行javascript 代碼如下:

 this.executeScript = function(locatorType, locatorValue, script){
        var element = this.getElement(locatorType, locatorValue);
        try{
            browser.executeScript(script, element);
        }
        catch(e){
        }
    };

我從頁面腳本中的函數調用此函數,如下所示:

this.clickLoginButton = function(){     elementController.executeScript(commonFunction.getValueFromJson(elementLandingPage,'landingPage.loginButton.locator'),
            commonFunction.getValueFromJson(elementLandingPage,'landingPage.loginButton.value'),"arguments[0].click();");
    };  

使用protractor執行測試腳本時,網頁上沒有任何反應。 其他功能(如輸入用戶名和密碼)也不起作用。 當使用webdriver直接單擊API單擊元素時,對我來說是有效的。 僅當我嘗試執行javascript時才會發生此問題。

長時間等待后,命令提示符上顯示以下錯誤:

<--- Last few GCs --->

  220607 ms: Mark-sweep 1387.6 (1435.4) -> 1385.7 (1435.4) MB, 27.7 / 0 ms [all
cation failure] [GC in old space requested].
  220637 ms: Mark-sweep 1385.7 (1435.4) -> 1385.7 (1435.4) MB, 31.0 / 0 ms [all
cation failure] [GC in old space requested].
  220667 ms: Mark-sweep 1385.7 (1435.4) -> 1385.7 (1435.4) MB, 28.6 / 0 ms [las
 resort gc].
  220688 ms: Mark-sweep 1385.7 (1435.4) -> 1385.7 (1435.4) MB, 27.2 / 0 ms [las
 resort gc].


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 000000C4BBFB4639 <JS Object>
    1: wrapCallSite(aka wrapCallSite) [C:\Users\abhinav.s\AppData\Roaming\npm\n
de_modules\protractor\node_modules\source-map-support\source-map-support.js:~30
] [pc=0000025812D46013] (this=000000C4BBF041B9 <undefined>,frame=00000260792131
1 <a CallSite with map 000002B62D3ACC21>)
    2: /* anonymous */(aka /* anonymous */) [C:\Users\abhinav.s\AppData\Roaming
npm\node_modules\protractor\node_...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

有人可以讓我知道解決方案。

更改browser.executeScript(script, element); browser.executeScript(script, element.getWebElement()); 解決了問題。

正確的代碼如下:

this.executeScript = function(locatorType, locatorValue, script){
        var element = this.getElement(locatorType, locatorValue);
        try{
            browser.executeScript(script, element.getWebElement());
        }
        catch(e){
        }
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM