Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
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 Jun 8 '12 at 17:28
@SamWoods it did throw an exception, stating, the element was not found.. – Mannii88 Jun 8 '12 at 17:56
Did you try driver.findElement(By.xpath("//canvas")).click()? – user246 Jun 8 '12 at 18:27
@user246, not working...modified and tried.!:) – Mannii88 Jun 8 '12 at 20:47
I will add the source code part for that canvas region...Hope, that will help ! – Mannii88 Jun 8 '12 at 20:58

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

share|improve this answer
up vote 0 down vote accepted

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...

share|improve this answer

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)
share|improve this answer
thanks for the answer..!!:) late thanks though..:) – Mannii88 Aug 18 '13 at 12:08
what is wbCanvas in here – Kumrun Nahar Keya Oct 1 '15 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)
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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