Thursday, 1 October 2015

Draw in canvas using selenium web driver and java

Drawing 3 points which will create a polygon


WebElement element = driver.findElement(By.xpath("html/body/div[3]/div[2]/div[2]/div[2]/div/canvas"));

Actions builder = new Actions(driver);
    Action drawAction = builder.moveToElement(element,135,15)  // start point in the canvas
    //signatureWebElement is the element that holds the signature element you have in the DOM
              .click()
              .moveByOffset(200, 60) // second point
              .click()
              .moveByOffset(100, 70) // third point
              .doubleClick()
              .build();
    drawAction.perform();

4 comments: