How can I access the canvas element without an id?

casperjs, css-selectors, dom, frontend, javascript

Solution

You can use CSS selectors:

document.querySelector('#derp canvas')

Problem

Using CasperJs, I'm trying to do some testing on canvas, by grabbing it and using `canvas.toDataURL();`. However, the canvas does not have an id, the code looks something like this: ``` <div id= 'derp' ...> <canvas ...> </canvas> </div> ``` Can I still get the canvas using something like ``` var canvas = document.getElementById(????); ``` or is there a better way of grabbing the canvas?

Original source