# Автоматизация Canvas элементов.

Одним из нововведений HTML 5 был тег < canvas >, с помощью которого можно было создавать различные графики и рисунки используя JavaScript. Многие разработчики стали активно его применять при создании веб-приложений. Поэтому любой автоматизатор может легко оказаться на проекте, где нужно будет автоматизировать работу и с Canvas элементами. Так давайте поробуем с помощью Selenium WebDiver это сделать:

```
@Test
public void testHTML5CanvasDrawing() throws Exception {
    //Get the HTML5 Canvas Element
    WebElement canvas = driver.findElement(By.id("imageTemp"));

    //Select the Pencil Tool
    Select drawtool = new Select(driver.findElement(By.id("dtool")));
    drawtool.selectByValue("pencil");

    //Create a Action Chain for Draw a shape on Canvas
    Actions builder = new Actions(driver);
    builder.clickAndHold(canvas).moveByOffset(10, 50).
                                    moveByOffset(50,10).
                                    moveByOffset(-10,-50).
                                    moveByOffset(-50,-10).release().perform();

    //Get a screenshot of Canvas element after Drawing and
    //compare it to the base version to verify if the Drawing is performed
    FileUtils.copyFile(WebElementExtender.captureElementBitmap(canvas), new File("c:\\tmp\\post.png"));
    assertEquals(CompareUtil.Result.Matched, CompareUtil.CompareImage("c:\\tmp\\base_post.png", "c:\\tmp\\post.png"));
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://comaqa.gitbook.io/selenium-webdriver-lectures/selenium-webdriver.-testirovanie-html5-veb-prilozhenii/avtomatizaciya-canvas-elementov..md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
