protratcor:使用executescript在元素上执行javascript的问题

protratcor:使用executescript在元素上执行javascript的问题,javascript,selenium,webdriver,protractor,Javascript,Selenium,Webdriver,Protractor,我已经编写了以下代码来在元素上执行javascript。代码如下: this.executeScript = function(locatorType, locatorValue, script){ var element = this.getElement(locatorType, locatorValue); try{ browser.executeScript(script, 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();");
    };  
this.executeScript = function(locatorType, locatorValue, script){
        var element = this.getElement(locatorType, locatorValue);
        try{
            browser.executeScript(script, element.getWebElement());
        }
        catch(e){
        }
};
我从页面脚本中的函数调用此函数,如下所示:

 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();");
    };  
this.executeScript = function(locatorType, locatorValue, script){
        var element = this.getElement(locatorType, locatorValue);
        try{
            browser.executeScript(script, element.getWebElement());
        }
        catch(e){
        }
};
使用
量角器执行测试脚本时,网页上不会发生任何事情。其他功能,如输入用户名和密码也不起作用。当我使用
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

220607毫秒:标记扫描1387.6(1435.4)->1385.7(1435.4)MB,27.7/0毫秒[全部
阳离子故障][请求旧空间中的GC]。
220637毫秒:标记扫描1385.7(1435.4)->1385.7(1435.4)MB,31.0/0毫秒[全部
阳离子故障][请求旧空间中的GC]。
220667毫秒:标记扫描1385.7(1435.4)->1385.7(1435.4)MB,28.6/0毫秒[las
度假酒店[gc]。
220688毫秒:标记扫描1385.7(1435.4)->1385.7(1435.4)MB,27.2/0毫秒[las
度假酒店[gc]。
==JS堆栈跟踪=========================================
安全上下文:000000 C4BBFB4639
1:wrapCallSite(又名wrapCallSite)[C:\Users\abhinav.s\AppData\Roaming\npm\n
de_modules\dragrator\node_modules\source map support\source map support.js:~30
][pc=0000025812D46013](此=000000C4BBF041B9,帧=00000260792131
1 )
2:/*匿名*/(aka/*匿名*/)[C:\Users\abhinav.s\AppData\Roaming
npm\节点\模块\量角器\节点\模块。。。
致命错误:调用和重试上次分配失败-进程内存不足

有人能告诉我这个问题的解决方案吗。

浏览器.executeScript(脚本,元素);
更改为
浏览器.executeScript(脚本,元素.getWebElement());
解决了这个问题

正确代码如下:

 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();");
    };  
this.executeScript = function(locatorType, locatorValue, script){
        var element = this.getElement(locatorType, locatorValue);
        try{
            browser.executeScript(script, element.getWebElement());
        }
        catch(e){
        }
};