Here I am trying to automate a salesforce page in which it contains of canvas salesforce locators , Does anyone know about this?
canvas 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.
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)
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.