首页 文章

带有selenium的HTML单元驱动程序不单击该按钮

提问于
浏览
0

我想在html单元驱动程序中单击带有onclick标签的元素 . 但它没有用 .

Page source:

我尝试了以下方法 .

  • 点击方法;

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

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

使用提交按钮时出错:

响应消息:javax.script.ScriptException:源文件:内联评估: 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;进口组织 . . . . '':dripBoxbutton .submit()

目标异常:内联评估中的java.lang.StackOverflowError:``import org.openqa.selenium.By; import org.openqa.selenium.WebDriver;进口组织 . . . . ''在第48行

响应标头:

  • 密钥发布

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);

使用kye版本时出错:

响应消息:javax.script.ScriptException:源文件:内联评估: 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;进口组织 . . . . 第49行的'' : dripBoxbutton .sendKeys ( Keys .ENTER ) in inline evaluation of: ``import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org. . . . ''

Response headers:
  • 动作方法;
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();

如何找到一种方法来单击Html单元驱动程序中的按钮 .

1 回答

  • 0

    您收到的错误表明存在语法问题,您可以通过将代码放入try block来获得更多信息性的堆栈跟踪:

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

    这样您就可以在jmeter.log文件中查看问题的根本原因 .

    特别是你的情况我的期望是你正在使用一些Beanshell语言不支持的功能 . 您可以尝试切换到 Groovy - 最有可能它会自动解决您的问题:

    JMeter WebDriver Groovy

    此外,根据JMeter Best Practices,您应该在JMeter中使用Groovy进行任何脚本编写任务,主要是因为Groovy has better performance than other JMeter scripting options .

相关问题