0

We have an application in which there is a canvas element. Inside that canvas element, there are lots of elements like boxes, arrows line etc. which we need to interact like clicking , dragging etc.

Is there any way to access the elements inside the Canvas element using Selenium Webdriver ?

Basically this is the only thing which I can see in the DOM if I inspect that Canvas element using developer tool

<canvas id="canvas1" tabindex="0" width="988" height="225" class="infa-canvas infa-graphical-canvas infa-template-canvas"></canvas>

I have been trying to google it out but unable to find any concrete answer. Some suggested to interact with those element on the basis of Coordinate which I don't want to. Also I was looking at this video https://www.youtube.com/watch?v=yugolxP3rhc where it recommended to talk to development team for some kind of hooks but I can't talk to developers as they belong to different company and are not approachable..

Any help is highly appreciated. Thanks.

Naseem
  • 911
  • 5
  • 18
  • 48
  • Is your canvas inside an iFrame? – Doug Clark Jan 11 '19 at 20:14
  • No, its not.... – Naseem Jan 11 '19 at 20:18
  • Dang. Can you post what you've tried so far? – Doug Clark Jan 11 '19 at 20:19
  • Basically I have been trying to google it out but unable to find any concrete answer. Some suggested to interact with those element on the basis of Coordinate which I don't want to. Also I was looking at this video https://www.youtube.com/watch?v=yugolxP3rhc where it recommended to talk to development team for some kind of hooks but I can't talk to developers as they belong to different company and are not approachable.. – Naseem Jan 11 '19 at 20:25
  • You might be stuck with coordinates, sorry cat – Doug Clark Jan 11 '19 at 20:33
  • 1
    There is nothing in your canvas except pixels. That's the whole point of the canvas: to be a 2D/3D pixel drawing surface. Once you draw a rectangle, there is no "rectangle", there is only "the same pixels as before, and now some of them have different byte values for their r/g/b/a component(s)". So if you want to work with the actual objects that are getting drawn on the canvas, "the canvas itself" is entirely irrelevant and you'll need to show some code to help explain when you mean when you're talking about having "elements". – Mike 'Pomax' Kamermans Jan 11 '19 at 20:35
  • I can't post the code here as it's proprietary thing but when I try to inspect the elements inside that canvas, I am just getting the property which I posted above. Can we use Console window from developer tool to access its property? I am getting some property of that Canvas when I type document.getElementByID('canvas1').getContext('2d') but it's huge and I am unable to understand its...Any help in that ? – Naseem Jan 13 '19 at 08:43

0 Answers0