I used below code with multiple points but still its not even drawing a dot on canvas. It is not even recognizing the element. Any other options to automate?

WebElement element = driver.findElement(By.xpath("xpath of canvas"));

Actions builder = new Actions(driver);
Action drawAction = builder.moveToElement(element,135,15) //start points x axis and y axis. 
          .moveByOffset(200, 60) // 2nd points (x1,y1)
          .moveByOffset(100, 70)// 3rd points (x2,y2)
  • 1
    What error are you getting? If the element is not being found, you may need a different XPath. Can you update your answer to add the HTML code and your XPath, so we have enough information to help you? – Kate Paulk Mar 24 '20 at 12:52
  • It just ignores that field not even writing a dot there. Also, no error is thrown. Xpath is "//canvas['signature']". – User58 Mar 24 '20 at 13:08
  • Please update your question and include the html that you're working with. Another thing you can try is to log the properties of the element. That will help to tell you if you've got the addressing correct. – Kate Paulk Mar 24 '20 at 13:34
  • Please update the error you are getting . this looks like xpath issue check your xpath – Hemant Varhekar Mar 24 '20 at 14:32
  • Have you seen sqa.stackexchange.com/questions/42846/… ? This feels like a duplicate question. – Lee Jensen Mar 24 '20 at 16:02

Use click and hold instead of click, the click will just click the mouse and releases it suddenly.

The below code is an example:

           WebDriver driver = new ChromeDriver();
           driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS) ;

           Actions builder = new Actions(driver);
           Action drawAction = builder.moveToElement(driver.findElement(By.cssSelector("[id='newSignature']"))) //start points x axis and y axis. 
                     .moveByOffset(-50, 60) // 2nd points (x1,y1)
                     .moveByOffset(-60, -70)// 3rd points (x2,y2)
                     .moveByOffset(150, 60) // 2nd points (x1,y1)
                     .moveByOffset(-60, -70)// 3rd points (x2,y

Read more about action class at :


  • Click and Hold also did not work. I presume, it is something to do with development team exposing elements. – User58 Apr 1 '20 at 12:54
  • @User58 your offset is calculated from the top left corner , so try using smaller number like 10,10 instead of 200 to make sure if it's working or not – PDHide Apr 1 '20 at 13:16
  • Top left of canvas element , not the entire Page – PDHide Apr 1 '20 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.