如何使用SeleniumWebDriver在画布上移动鼠标进行绘制
我想自动绘制画布元素。我已经写了一个测试用例&它通过了 但在我的代码中,我编写了选择绘图工具的函数&在画布上画一条简单的线。已选择“结束绘制”工具,但未绘制直线。如何使用SeleniumWebDriver在画布上移动鼠标进行绘制,selenium,Selenium,我想自动绘制画布元素。我已经写了一个测试用例&它通过了 但在我的代码中,我编写了选择绘图工具的函数&在画布上画一条简单的线。已选择“结束绘制”工具,但未绘制直线。 以下是守则- public void DrawLine() { wait.until(ExpectedConditions.elementToBeClickable(anotate_draw)); action.click(anotate_draw).perform(); action.cli
以下是守则-
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();
}
你可能已经自己回答了这个问题。但这可能也适用于您:
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();
这很有帮助,但至少在我的例子中存在一个问题,Selenium的速度太快,而不仅仅是在画布内的区域标记点。也许你需要使用ClickAndHold(IWebElement)然后移动。