Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - How to click on canvas in selenium?

Tags:

click

selenium

I have a canvas element (Width: 720, Height : 174). This canvas has 16 parts. I tried

Actions.moveToElement(we,(720/16)*3,1).click().perform(); 

I want it to click in part 3 of the canvas, but it always clicks in the first part. Please help!

like image 727
sonas sonas Avatar asked Sep 06 '25 23:09

sonas sonas


2 Answers

Try

Actions.moveToElement(we,0,0).moveByOffset((720/16)*3,1).click().build().perform(); 
like image 102
alexey.chumagin Avatar answered Sep 09 '25 08:09

alexey.chumagin


For getting co-ordinates of the elements inside canvas tag use any online ruler

Actions clickAt = new Actions(d);
clickAt.moveToElement(d.findElement(By.xpath("your canvas id here")), 60, 30).click();
clickAt.moveToElement(d.findElement(By.xpath("your canvas id here")), 90, 30).click();
clickAt.build().perform();
like image 26
Alok Sharma Avatar answered Sep 09 '25 09:09

Alok Sharma