简体   繁体   中英

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

I have written below code to execute javascript on an element. The code is as below:

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

I am calling this from a function in page script as below:

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

On executing the test script using protractor nothing happens on web page. Other functions like entering username and password are also not working. While clicking on element using direct click API of webdriver is working fie for me. This issue only occurs when I try to execute javascript .

Following error is shown on command prompt after long wait:

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

Can someone let me know solution for this.

Changing browser.executeScript(script, element); to browser.executeScript(script, element.getWebElement()); solved the problem.

Correct code is as below:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM