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