Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grabbing <canvas> pixels through Selenium / Python

I am doing some automation on the sever side. I'd like to somehow interact with the HTML page through Python code and access the pixel data. What kind of options Selenium offers for his kind of approaches?

Possible considerations

  • Raw pixel data access in in-process memory

  • Get pixels by saving them to a local image file (PNG)

  • Get pixels by saving them to a memory, listening port on localhost and pushing the data there over AJAX

  • Creating an image file and accessing it directly in-process memory

like image 780
Mikko Ohtamaa Avatar asked Nov 05 '22 19:11

Mikko Ohtamaa


1 Answers

Using Selenium you can query the canvas for its image data using Selenium's getEval method (ref) with some smartly designed js code.

You can do it pixel by pixel if that's what you want, or just grab the entire canvas using the toDataURL method.

like image 52
Variant Avatar answered Nov 09 '22 07:11

Variant