Quality Testing

Quality is delighting customers


In my project, I need to click on an image drawn in the canvas. I am able to do it with coordinates. But that is not the right way to do, because each time different images with different size, gets loaded.

So sometimes there will be empty space around the image on canvas depending on the height and width of that image. And this image cannot be located through DOM.

Is there any way for Selenium to find the boundaries of these images which gets loaded(dynamic)? So that I can mouse click within the image.

Thank You


Views: 248

Reply to This

Replies to This Discussion


Look at my thread in Utest - https://www.utest.com/forums/13758/page/1?sort=oldest

Might help u:)

Test Scenario: Verify an image can be drawn and compared successfully

Solution: Since drawing is an action, we can use the Selenium Webdriver’s action class to automate the canvas feature.
Approach: Draw an image and save it in some location. Draw the same image using selenium automation and compare the same with a saved image.

Steps to automate:

1. TestNG is one of the best unit testing tool to drive the Selenium java tests. First create a test using TestNG
public void testCanvasHtml5() throws Exception {
code for automation

2. Find the canvas element by it’s id
WebElement canvasElement = driver.findElement(By.id(“<id>”));

3. Select a tool to draw an image on the canvas
//Select the Pencil Tool
Select toolDraw = new Select(driver.findElement(By.id(“<tool’s id>”)));

4. Create an action class and use mouse movements to draw the image
Actions builder = new Actions(driver);
builder.clickAndHold(canvasElement).moveByOffset(10, 50).

5. Take a screen shot of the drawn image
FileUtils.copyFile(WebElementExtender.captureElementBitmap(canvasElement),new File(“automatedImageFile”));

6. Comparison and verification using TestNG

for more information:http: //qaplanet.in/courses-overview/selenium-training/ 


TTWT Magazine





© 2018   Created by Quality Testing.   Powered by

Badges  |  Report an Issue  |  Terms of Service