Handling Canvas in Selenium

54 views
Skip to first unread message

Harsh Bedi

unread,
May 31, 2018, 2:50:26 AM5/31/18
to Selenium Users
Need help to handle Canvas in Selenium.

I am working on a website, it have canvas & different buttons present on it.But in DOM id for these buttons are not present its only the Canvas tag.
Please help me how can i get id of an element present on Canvas.

Joe Ward

unread,
May 31, 2018, 6:12:21 AM5/31/18
to seleniu...@googlegroups.com
You can't. Things drawn on a variable size canvas element are part of the same canvas element, not different elements in their own right.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/c95954ff-6ace-4a14-836e-d80757215c3a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Harsh Bedi

unread,
May 31, 2018, 6:23:35 AM5/31/18
to seleniu...@googlegroups.com
Thanks for the reply Joe. But how should I write selenium code around this then.
How should I click on some element present on canvas then.

Thanks in advance

On Thu 31 May, 2018, 3:42 PM Joe Ward, <ddl...@gmail.com> wrote:
You can't. Things drawn on a variable size canvas element are part of the same canvas element, not different elements in their own right.
On 31 May 2018 at 07:49, Harsh Bedi <harsh...@gmail.com> wrote:
Need help to handle Canvas in Selenium.

I am working on a website, it have canvas & different buttons present on it.But in DOM id for these buttons are not present its only the Canvas tag.
Please help me how can i get id of an element present on Canvas.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAJPyTs3-8zxemmmM8MtjJTqKVbNCiTvBN6t4q3WmV5swdZ%3DMmg%40mail.gmail.com.

David

unread,
May 31, 2018, 3:56:08 PM5/31/18
to Selenium Users
Is this canvas a fixed size regardless of how browser is resized? And are the elements inside at fixed locations? If so, you might be able to use Selenium API or javascript to click at x,y offset from canvas (top left corner I believe). And if that doesn't work, you have option of looking into 3rd party image based tools like Sikuli, etc. to also click at offset from known image (the canvas).

Another option is to research into whether you can manipulate the elements inside the SVG via javascript, e.g. get it's object handle, click it, etc. That could be easier if your organization owns the canvas widget/element.

Joe Ward

unread,
Jun 1, 2018, 2:25:33 AM6/1/18
to seleniu...@googlegroups.com
David has this exactly right IMO!

To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/1a64e51e-93fd-4a09-b254-3d4cff8130e8%40googlegroups.com.

Harsh Bedi

unread,
Jun 1, 2018, 2:57:43 AM6/1/18
to seleniu...@googlegroups.com
Appreciate the help David  & Joe. I think i can make progress now. :)

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+unsubscribe@googlegroups.com.
To post to this group, send email to selenium-users@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Thanks & Regards
Harsh Bedi
Reply all
Reply to author
Forward
0 new messages