如何使用selenium webdriver在画布上移动鼠标进行绘制

时间:2016-01-27 08:41:58

标签: selenium

我想在canvas元素上自动绘图。我写了一个测试用例&它过去了。

但是在我的代码中,我编写了选择绘图工具和功能的功能。在画布上画一条简单的线。最后选择绘图工具但不绘制线 以下是代码 -

public void DrawLine() {    
wait.until(ExpectedConditions.elementToBeClickable(anotate_draw));    
    action.click(anotate_draw).perform();     
    action.clickAndHold(canvas_page1)
    .moveByOffset(420, 280)    
    .moveByOffset(550,300)  
    .release().build().perform();
}

1 个答案:

答案 0 :(得分:1)

你可能已经自己回答了这个问题。但这也可能对你有用:

WebElement element = driver.findElement(By.xpath("Your xPath")); // where your canvas element is 

    Actions builder = new Actions(driver);
    Action drawAction = builder.moveToElement(element,50,50)  // start point
                 .click()
                 .moveByOffset(100, 60) // second point
                 .doubleClick()
                 .build();
       drawAction.perform();
相关问题