How can I access the canvas element without id?

Using CasperJs, I am trying to do some testing on a canvas by capturing it and using canvas.toDataURL(); . However, there is no identifier on the canvas, the code looks something like this:

 <div id= 'derp' ...> <canvas ...> </canvas> </div> 

Can I get a canvas using something like

 var canvas = document.getElementById(????); 

or is there a better way to capture the canvas?

+4
source share
1 answer

You can use the CSS selector:

 document.querySelector('#derp canvas') 
+6
source

Source: https://habr.com/ru/post/1497255/


All Articles