简体   繁体   English

使用Jmeter在Selenium中执行Java脚本时方法调用错误

[英]Error in method invocation when executing java scripts in selenium using jmeter

I'm getting following error while try to execute the java script within my selenium code. 尝试在我的硒代码中执行Java脚本时遇到以下错误。

Error: Response message: javax.script.ScriptException: Sourced file: inline evaluation of: import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org. . . . '' : Typed variable declaration : Error in method invocation: Method executeScript( java.lang.String ) not found in class'org.openqa.selenium.htmlunit.HtmlUnitDriver' : at Line: 47 : in file: inline evaluation of: 错误:响应消息:javax.script.ScriptException:源文件:内联评估: import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org. . . . '' : Typed variable declaration : Error in method invocation: Method executeScript( java.lang.String ) not found in class'org.openqa.selenium.htmlunit.HtmlUnitDriver' : at Line: 47 : in file: inline evaluation of: import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org. . . . '' : Typed variable declaration : Error in method invocation: Method executeScript( java.lang.String ) not found in class'org.openqa.selenium.htmlunit.HtmlUnitDriver' : at Line: 47 : in file: inline evaluation of: import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org. . . . '' : Typed variable declaration : Error in method invocation: Method executeScript( java.lang.String ) not found in class'org.openqa.selenium.htmlunit.HtmlUnitDriver' : at Line: 47 : in file: inline evaluation of: import org.openqa.selenium.By; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org. . . . '' : Typed variable declaration : Error in method invocation: Method executeScript( java.lang.String ) not found in class'org.openqa.selenium.htmlunit.HtmlUnitDriver' : at Line: 47 : in file: inline evaluation of: import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; 导入org.openqa.selenium.WebDriver; import org. 导入组织。 . . . '' : executor .executeScript ( "document.getElementById('icon-2')[0].click()" ) in inline evaluation of: ``import org.openqa.selenium.By; '':执行器.executeScript(“ document.getElementById('icon-2')[0] .click()”)的内联评估:``import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; 导入org.openqa.selenium.WebDriver; import org. 导入组织。 . . . '' at line number 47 ''在第47行

Response headers: 响应头:

Code: 码:

public HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.CHROME,true);
JavascriptExecutor executor = (JavascriptExecutor)driver;
driver.get(appURL);
executor.executeScript("document.getElementById('icon-2')[0].click()");

How do I execute the java script within selenium? 如何在Selenium中执行Java脚本?

Page dom structure : 页面dom结构:

It seems that Beanshell interpreter doesn't support varargs therefore your attempt to call executeScript() method whose 2nd parameter is java.lang.Object... args is failing. 似乎Beanshell解释器不支持varargs,因此您尝试调用其第二个参数为java.lang.Object... args executeScript()方法失败。

The easiest solution is switching to Groovy language as: 最简单的解决方案是按以下方式切换到Groovy语言:

  1. It is recommended by JMeter developers JMeter开发人员推荐
  2. Groovy supports all modern JDK features and has its own syntax sugar on top Groovy支持所有现代JDK功能,并且在顶部具有自己的语法糖
  3. Groovy performs much better comparing to Beanshell 与Beanshell相比,Groovy的性能要好得多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:方法调用期间引发了 Java 异常 - Error: Java exception was raised during method invocation Jmeter + Selenium API-Java脚本解除错误 - Jmeter + selenium api - Java script undled error 使用Jmeter / Blazemeter时,出现错误org.openqa.selenium.NoSuchElementException:无法找到元素: - When using Jmeter/ Blazemeter I get the error org.openqa.selenium.NoSuchElementException: Unable to locate element: 开玩笑错误:调用方法时测试 ES6 class 调用 - Jest Error: Test ES6 class invocation when calling method 使用Java或任何其他语言加载和执行jquery和javascript脚本 - Loading and Executing the jquery and javascript scripts using Java or any other language 执行传递的函数时非法调用 - Illegal invocation when executing passed function 单击方法不起作用 - 使用 selenium webdriver 和 java - Click method not working - using selenium webdriver with java 用于滚动的 executeScript() 方法抛出错误,因为 null 无法使用 Selenium Java 创建 object - executeScript() method for scrolling throws error as null cannot create object using Selenium Java 在jmeter中使用转义字符时的Java强制文字 - java force literal when using escape character in jmeter HTML 异步脚本何时*完成*执行? - When do HTML async scripts *finish* executing?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM