Java 使用selenium web驱动程序在画布中绘制不工作

Java 使用selenium web驱动程序在画布中绘制不工作,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,我写了下面的内容,只是为了在画布上画任何东西,但它不起作用 Actions builder = new Actions(browser); Action drawAction = builder.moveToElement(webElement,135,15) //start points x axis and y axis. .click() .moveByOffset(200, 60) // 2nd points (x1,y1) .click()

我写了下面的内容,只是为了在画布上画任何东西,但它不起作用

 Actions builder = new Actions(browser);
 Action drawAction = builder.moveToElement(webElement,135,15) //start points x axis and y axis.
     .click()
     .moveByOffset(200, 60) // 2nd points (x1,y1)
     .click()
     .moveByOffset(100, 70) // 3rd points (x2,y2)
     .doubleClick()
     .build();
drawAction.perform();
在调试模式下,这可以工作,但通常不会。有时有效,有时无效

因此DOM中有一个canvas元素,下面是HTML代码

 <fieldset class="signature kyc-signature odd field_with_errors has-
   drawn" data-field="Registration::Field::Signature" data-field-
  name="registration[signatureImageData]" data-name="
  [["legalPerson","firstName"],["legalPerson","lastName"]]">
  <label class="fieldset-label" for="signatureImageData-1a9012cc">
  </label>
 <div class="signature-well">
 <input id="registration_signatureImageData" 
  name="registration[signatureImageData]" value="<?xml version="1.0" 
   encoding="UTF-8" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD 
   SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg 
  xmlns="http://www.w3.org/2000/svg" version="1.1" width="62" 
      height="52"><path fill="none" stroke="#000000" stroke-width="2" 
 stroke-linecap="round" stroke-linejoin="round" d="M 61 1 l 1 1"/><path 
 fill="none" stroke="#000000" stroke-width="2" stroke-linecap="round" 
  stroke-linejoin="round" d="M 1 51 l 1 1"/></svg>" type="hidden">
  <a class="clear" href=""></a>
  <div class="signature-container" data-sign-here="">
  <div style="padding:0 !important;margin:0 !important;width: 100% 
  !important; height: 0 !important;margin-top:-1em !important;margin-
  bottom:1em !important;"></div>
   <canvas class="jSignature" style="margin: 0px; padding: 0px; border: 
 medium none; height: 180px; width: 769px;" width="769" height="180">
  </canvas>
     <div style="padding:0 !important;margin:0 !important;width: 100% 
 !important; height: 0 !important;margin-top:-1.5em !important;margin-
 bottom:1.5em !important;"></div>
 </div>
 <div class="name-underlined"> </div>
</div>
<div class="signature-description"> </div>

运行代码时,绘制画布代码有时有效,有时无效

使用下面的代码等待画布元素可见

 public WebElement waitForElementToBeVisible() {
        logger.info("[WaitForElement][Visibility][" + waitTime + "s] " + 
       formatLocator());

        // important: nullify implicitlyWait()
        browser.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);

        // wait for element
        Wait<WebDriver> wait = new WebDriverWait(browser, waitTime);
        wait.until(new ExpectedCondition<WebElement>() {
            public WebElement apply(WebDriver browser) {
                try {
                    findElement(false);
                } catch (Exception e) {
                    logger.error("Exception while waiting on: " + locator + 
            " " + e.getClass().getName() + ":" + e.getMessage());
                }
                if (webElement != null && !webElement.isDisplayed()) {
                    webElement = null;
                }
                return webElement;
            }

            public String toString() {
                return String.format("element %s(%s) to be visible", 
           locator, locator.getLocator());
            }
            });
公共WebElement WaitForElementToBeviible(){
logger.info(“[WaitForElement][Visibility][”+waitTime+“s]”的+
formatLocator());
//重要提示:隐式null化wait()
browser.manage().timeouts().implicitlyWait(0,TimeUnit.SECONDS);
//等待元素
Wait Wait=新的WebDriverWait(浏览器,waitTime);
等待.直到(新的ExpectedCondition(){
公共WebElement应用(WebDriver浏览器){
试一试{
findElement(假);
}捕获(例外e){
logger.error(“等待时异常:”+locator+
“+e.getClass().getName()+”:“+e.getMessage());
}
if(webElement!=null&&!webElement.isDisplayed()){
webElement=null;
}
返回webElement;
}
公共字符串toString(){
返回String.format(“元素%s(%s)可见”,
定位器,locator.getLocator());
}
});

您还没有给我们提供任何关于这应该做什么的上下文。您做过任何调试吗?您尝试了什么?结果如何?我不确定我们应该如何帮助您完成这项工作。您确定所有这些坐标都在CANVAS元素中吗?如果是间歇性的,您确定在开始之前CANVAS在那里/可见/可交互吗rt动作?滚动到视图就成功了,因为元素不在视图中。有人知道如何在Laravel Dash中实现这一点吗?
 public void drawCanvas() {
        Actions builder = new Actions(browser);
        JavascriptExecutor executor = (JavascriptExecutor) browser;
        executor.executeScript("arguments[0].scrollIntoView();", webElement); //Scroll the page and move where the element is located
        Action drawAction = builder.moveToElement(webElement, 135, 15) //start points x axis and y axis.
                .click()
                .moveByOffset(200, 80) // 2nd points (x1,y1)
                .click()
                .moveByOffset(100, 100)// 3rd points (x2,y2)
                .doubleClick()
                .build();
        drawAction.perform();
    }