Can I draw on canvas using Selenium Python?


PhD

I'm trying to run automated tests and benchmarks for an HTML5 canvas application. I've setup Selenium with python-unittest and ChromeDriver (though I'm open to alternatives).

Canvas apps are whiteboards where lines are drawn by clicking the mouse and dragging around the canvas. How to automatically draw simple shapes using Selenium? I went through the python-selenium API and the only mouse move test options pass ActionChains, but all of them are based on their idor move the mouse over the element class. I haven't seen a way to automatically move the mouse based on coordinates on the canvas.

Is there any way to implement automatic testing of painting on canvas?

ice axe

There is also a click_and_hold function. This worked for me:

from selenium.webdriver.common.action_chains import ActionChains

canvas = self.driver.find_element_by_id("myCanvas")
drawing = ActionChains(self.driver)\
    .click_and_hold(canvas)\
    .move_by_offset(-10, -15)\
    .move_by_offset(20, 32)\
    .move_by_offset(10, 25)\
    .release()
drawing.perform()

(where self.driver is my Selenium Webdriver.)

Related


Can I draw a class's path on a canvas using JavaScript?

Georgetown I use the beginPath() method to randomly draw small stars on the canvas like this: function makeStars(){ for(let i=0; i<100; i++){ let startingX = Math.floor(Math.random()*canvasWidth); let startingY = Math.floor(Math.random()*canvasHeight

I can't draw rectangle using canvas as child component

Riddle I need to draw a rectangle using canvas. Canvas must be in child component. Just like the updateCanvas function. Is it possible to do so? I am trying to draw a rectangle in the parent component and everything works fine, but in this case I need to put t

I can't draw rectangle using canvas as child component

Riddle I need to draw a rectangle using canvas. Canvas must be in child component. Just like the updateCanvas function. Is it possible to do so? I am trying to draw a rectangle in the parent component and everything works fine, but in this case I need to put t

Can I draw a class's path on a canvas using JavaScript?

Georgetown I use the beginPath() method to randomly draw small stars on the canvas like this: function makeStars(){ for(let i=0; i<100; i++){ let startingX = Math.floor(Math.random()*canvasWidth); let startingY = Math.floor(Math.random()*canvasHeight

Why can't I draw a square on the canvas?

Lords Hey, I'm making a snake game in JS, and now all I want to do is draw a snake in the center of the canvas. I've set the canvas size to the board size, so everything scales correctly, but nothing shows up. Any help would be greatly appreciated :) //declare

Why can't I draw a square on the canvas?

Lords Hey, I'm making a snake game in JS, and now all I want to do is draw a snake in the center of the canvas. I've set the canvas size to the board size, so everything scales correctly, but nothing shows up. Any help would be greatly appreciated :) //declare

Can't draw square on canvas using setInterval?

User 10870573 Hey guys, I'm trying to use setInterval to draw a square on the canvas every 70ms. Interval is set to call function draw()this function, which contains the fillRect() method. But I can't get it to work any ideas? Oh, I tried clearRect() but it di

Can't draw square on canvas using setInterval?

User 10870573 Hey guys, I'm trying to use setInterval to draw a square on the canvas every 70ms. Interval is set to call function draw()this function, which contains the fillRect() method. But I can't get it to work any ideas? Oh, I tried clearRect() but it di

Can't draw proper circle using canvas

Xiajin In any case, I can't get a proper circle to draw. I am always oval. Here is sample code to show you what I mean: function canvasClicked(number) { var c = "canvas" + number; var canvas = document.getElementById(c); var context = canvas.getContext("

Everything I draw on the canvas using Fabric is offset

username When I draw on the canvas using Fabric lib, everything is offset. Here is the code: Fcanvas = new fabric.Canvas('c'); var circle = new fabric.Circle({radius: 100, fill: 'green', left: 100, top: 100}); var triangle = new fabric.Triangle({width: 20, he

Everything I draw on the canvas using Fabric is offset

username When I draw on the canvas using Fabric lib, everything is offset. Here is the code: Fcanvas = new fabric.Canvas('c'); var circle = new fabric.Circle({radius: 100, fill: 'green', left: 100, top: 100}); var triangle = new fabric.Triangle({width: 20, he

Everything I draw on the canvas using Fabric is offset

username When I draw on the canvas using Fabric lib, everything is offset. Here is the code: Fcanvas = new fabric.Canvas('c'); var circle = new fabric.Circle({radius: 100, fill: 'green', left: 100, top: 100}); var triangle = new fabric.Triangle({width: 20, he

How can i draw tiles on canvas using p5.js

Ayman Ben I'm trying to make an html5 game using p5.js and the first thing I try to achieve is to draw a tilemap, but my code is not working. I'm using nested loops to draw tiles, but I need faster speed, I found another algorithm for drawing tiles using 1D ar

Using Canvas, how can I draw X times the shape of the user input?

Michael He I am trying to draw 30 rectangles, the nth rectangle is a number entered by the user. Each nth rectangle will be the color entered by the user. Here is what I have below: <script> let n = document.getElementById("number") let colors = document.getE

How can i draw tiles on canvas using p5.js

Ayman Ben I'm trying to make an html5 game using p5.js and the first thing I try to achieve is to draw a tilemap, but my code is not working. I'm using nested loops to draw tiles, but I need faster speed, I found another algorithm for drawing tiles using 1D ar

How can i draw tiles on canvas using p5.js

Ayman Ben I'm trying to make an html5 game using p5.js and the first thing I try to achieve is to draw a tilemap, but my code is not working. I'm using nested loops to draw tiles, but I need faster speed, I found another algorithm for drawing tiles using 1D ar

Using Canvas, how can I draw X times the shape of the user input?

Michael He I am trying to draw 30 rectangles, the nth rectangle is a number entered by the user. Each nth rectangle will be the color entered by the user. Here is what I have below: <script> let n = document.getElementById("number") let colors = document.getE

Using Canvas, how can I draw X times the shape of the user input?

Michael He I am trying to draw 30 rectangles, the nth rectangle is a number entered by the user. Each nth rectangle will be the color entered by the user. Here is what I have below: <script> let n = document.getElementById("number") let colors = document.getE

How can i draw tiles on canvas using p5.js

Ayman Ben I'm trying to make an html5 game using p5.js and the first thing I try to achieve is to draw a tilemap, but my code is not working. I'm using nested loops to draw tiles, but I need faster speed, I found another algorithm for drawing tiles using 1D ar

How can i draw tiles on canvas using p5.js

Ayman Ben I'm trying to make an html5 game using p5.js and the first thing I try to achieve is to draw a tilemap, but my code is not working. I'm using nested loops to draw tiles, but I need faster speed, I found another algorithm for drawing tiles using 1D ar

How can I draw an energy ranking graph using Python?

twin penguins This is a typical energy ranking used in some published papers, and I am struggling to reproduce one for my data using Python (any matplotlib, sns, etc.). I structure the data in a Pandas dataframe like this: System Color_id Data1 Data2 Form I