0
votes

I'm getting following error while try to execute the java script within my selenium code.

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:import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org. . . . '' : executor .executeScript ( "document.getElementById('icon-2')[0].click()" ) in inline evaluation of: ``import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org. . . . '' at line number 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?

Page dom structure :

1

1 Answers

0
votes

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.

The easiest solution is switching to Groovy language as:

  1. It is recommended by JMeter developers
  2. Groovy supports all modern JDK features and has its own syntax sugar on top
  3. Groovy performs much better comparing to Beanshell