# How can I automate the Canvas locators?

**URL:** <https://forum.robotframework.org/t/how-can-i-automate-the-canvas-locators/8568>\
**Category:** Robot Framework\
**Created:** [28 February 2025 05:26 UTC](https://forum.robotframework.org/t/how-can-i-automate-the-canvas-locators/8568 "2025-02-28T05:26:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abhi\_04](https://avatars.discourse-cdn.com/v4/letter/a/e47c2d/32.png) [@Abhi\_04](https://forum.robotframework.org/u/Abhi_04)\
**Post date:** [28 February 2025 05:26 UTC](https://forum.robotframework.org/t/how-can-i-automate-the-canvas-locators/8568/1 "2025-02-28T05:26:52Z")

</div>

Here I am trying to automate a salesforce page in which it contains of canvas salesforce locators , Does anyone know about this?

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [28 February 2025 06:42 UTC](https://forum.robotframework.org/t/how-can-i-automate-the-canvas-locators/8568/2 "2025-02-28T06:42:05Z")

</div>

[canvas](https://www.w3schools.com/html/html5_canvas.asp) is a HTML5 element, I’ve not had much success selecting them, especially with xpath, but also with css selectors I have trouble selecting inside a canvas (also svg elements are troublesome).

I usually go to the parent of the canvas/svg element and click that instead, from my experience with salesforce it’ll probably be a div and you can use the class of the div to select it.

The other approach I find works well with salesforce fields is to use an xpath to select relative to the label like these

- `//label[text()"LabelName"]/../..//input`
- `//span[text()"LabelName"]/../..//div`

Hope that helps,

Dave.

---

<div class="post-metadata">

**Author:** ![chevi](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/chevi/32/4681_2.png) [@chevi](https://forum.robotframework.org/u/chevi)\
**Post date:** [20 March 2025 12:57 UTC](https://forum.robotframework.org/t/how-can-i-automate-the-canvas-locators/8568/4 "2025-03-20T12:57:40Z")

</div>

You should write your own library on python with **OpenCV**. Logic in a few words: make screenshot of an icon, where you want to click and save it as template.png, make screenshot of the canvas, cv2 will find template.png on the canvas, get coordinates, selenium makes click there. The main challenge is if you want to play your autotests on the different computers (different resolution, fonts, etc. - might make fake fail in the tests)

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [20 March 2025 13:20 UTC](https://forum.robotframework.org/t/how-can-i-automate-the-canvas-locators/8568/5 "2025-03-20T13:20:07Z")

</div>

There are already a few libraries that do image recognition and give you the co-ordinates for the matching image, so no need to create one.

But in a HTML page where you can use xpath and css selectors, using these selectors is already easier, just find the location of the canvas by using a selector to it’s parent element.

With an application like salesforce there’s no need to click the canvas itself (usually an button or combobox icon), just send the click to the parent element.
