Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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, selenium.clickAt(), driver.findElement(By.xpath("/html/body/form/div/canvas")).click();

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

Source Code of the page, for the Canvas region:

<table>
<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'
      src='http://<pdftest.anotherwebsite.com>//signature/index.php?signid=<something>'
      class="required" ></iframe>
      <input type="hidden" name="ds" value="<something">
    </div>
  </div>
</td>
<td width="5%"  bgcolor="#D4D4D4"></td>
</tr>
<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>
</tr>
</table>

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
show 1 more comment

3 Answers 3

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
add comment
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
add comment

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
                .contextClick(wbCanvas)
                .moveToElement(wbCanvas,8,8)
                .clickAndHold(wbCanvas)
                .moveByOffset(120, 120)
                .moveByOffset(60,70)
                .moveByOffset(-140,-140)
                .release(wbCanvas)
                .build();
drawOnCanvas.perform();
share|improve this answer
    
thanks for the answer..!!:) late thanks though..:) –  Mannii88 Aug 18 '13 at 12:08
add comment

Your Answer

 
discard

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.