1
votes

I want to click a element with onclick tag in html unit driver. But it didn't work.

Page source:

I tried following method.

  1. click method;

    public HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.CHROME, true); driver.get(appURL); WebElement dripBoxbutton = driver.findElement(By.xpath("//img[@class='idp-image']/..")); dripBoxbutton.click();

  2. Submit method;

    public HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.CHROME, true);
    driver.get(appURL);
            WebElement dripBoxbutton = driver.findElement(By.xpath("//img[@class='idp-image']/.."));
                    dripBoxbutton.submit();
    

    Error when using submit button:

    Response message: javax.script.ScriptException: Sourced file: inline evaluation of: import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org. . . . '' : Method Invocation dripBoxbutton.submit : at Line: 48 : in file: inline evaluation of:import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org. . . . '' : dripBoxbutton .submit ( )

    Target exception: java.lang.StackOverflowError in inline evaluation of: ``import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org. . . . '' at line number 48

    Response headers:

    1. Key release

      import org.openqa.selenium.Keys; public HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.CHROME, true); driver.get(appURL); WebElement dripBoxbutton = driver.findElement(By.xpath("//img[@class='idp-image']/..")); dripBoxbutton.sendKeys(Keys.ENTER);

Error when using kye release:

Response message: javax.script.ScriptException: Sourced file: inline evaluation of: import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org. . . . '' : Error in method invocation: Method sendKeys( org.openqa.selenium.Keys ) not found in class'org.openqa.selenium.htmlunit.HtmlUnitWebElement' : at Line: 49 : in file: inline evaluation of:import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org. . . . '' : dripBoxbutton .sendKeys ( Keys .ENTER ) in inline evaluation of: ``import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org. . . . '' at line number 49

Response headers:
  1. action method;

     import org.openqa.selenium.interactions.Actions;
        public HtmlUnitDriver driver = new HtmlUnitDriver(BrowserVersion.CHROME, true);
        driver.get(appURL);
        WebElement webElement = driver.findElement(By.xpath("//img[@class='idp-image']/.."));
                Actions builder = new Actions(driver);
                builder.moveToElement(webElement).click(webElement);
    

    builder.perform();

How to find a way to click the button in Html unit driver.

1

1 Answers

0
votes

The error you're getting indicates a syntax problem, you can get more informative stacktrace by putting your code into try block like:

try {
    //your code here
}
catch (Throwable ex) {
    log.error("Failure in script", ex);
}

This way you will be able to see the root cause of your problem in jmeter.log file.

In particular your case my expectation is that you're using some function which is not supported by Beanshell language. You can try switching to Groovy - most probably it will automatically resolve your issue:

JMeter WebDriver Groovy

Moreover, according to JMeter Best Practices you should be using Groovy for any scripting tasks in JMeter mainly because Groovy has better performance than other JMeter scripting options.