I want to automate the testing for a digital signature, which is a canvas element.

Can anyone provide me with sample code, which could be used.

I have tried,


both threw an element not found exception for me...

Source Code of the page, for the Canvas region:

<tr class="tdbg" valign="middle"  bgcolor="#D4D4D4" height="1px">
<td width="5%" bgcolor="#D4D4D4"></td>
<td width="90%" bgcolor="#D4D4D4">
  <div align="center" id="electronicSignImage">
    <div>Please use mouse to draw your Signature &nbsp;</div>
    <div id="ds" align="center">
      <iframe id="elecsign"  align='middle' style="border:1px #9E9E9E solid;
      padding:10px;" height='180' width='200' scrolling='no'
      class="required" ></iframe>
      <input type="hidden" name="ds" value="<something">
<td width="5%"  bgcolor="#D4D4D4"></td>
<tr class="tdbg" valign="middle"  bgcolor="#D4D4D4" >
  <td width="5%" height="1px" bgcolor="#D4D4D4">&nbsp;</td>
  <td  bgcolor="#D4D4D4" height="1px" width="80%" >&nbsp;</td>
  <td width="5%" height="1px" bgcolor="#D4D4D4">&nbsp;</td>

Hope this helps!

  • When you say it didn't work, do you mean that it did not throw an exception, but did not do anything, or was there an exception stating that the element can not be found, or something else?
    – Sam Woods
    Commented Jun 8, 2012 at 17:28
  • @SamWoods it did throw an exception, stating, the element was not found..
    – Manikandan
    Commented Jun 8, 2012 at 17:56
  • Did you try driver.findElement(By.xpath("//canvas")).click()?
    – user246
    Commented Jun 8, 2012 at 18:27
  • @user246, not working...modified and tried.!:)
    – Manikandan
    Commented Jun 8, 2012 at 20:47
  • I will add the source code part for that canvas region...Hope, that will help !
    – Manikandan
    Commented Jun 8, 2012 at 20:58

4 Answers 4


Actually, the Canvas element was embedded in a Frame..So, had to switch to Frame and then click on the Canvas!! That was the solution, for the issue...


The Canvas element display issue in Selenium 2.28 has been solved in Selenium 2.29 version. The following code did work for me. The driver object is a Firefox driver.

Actions actionBuilder=new Actions(driver);          
Action drawOnCanvas=actionBuilder
                .moveByOffset(120, 120)
  • thanks for the answer..!!:) late thanks though..:)
    – Manikandan
    Commented Aug 18, 2013 at 12:08
  • what is wbCanvas in here Commented Oct 1, 2015 at 10:03

Drawing 3 points which will create a polygon and the last double click ends the drawing process code described bellow:

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)

Due to the fact that I'm a lazy coder, I always record my cases with Selenium IDE and find the best way to locate the WebElements I use.

Use the "Target" Dropdown to alter the way you address them and the "Find" Button to assure it's working.

Also make sure that you use the last version of Selenium/Browser

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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