sonas sonas
sonas sonas

Reputation: 197

Java - How to click on canvas in 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!

Upvotes: 4

Views: 10165

Answers (3)

Chaitanya Pathak
Chaitanya Pathak

Reputation: 1

  1. Include the Sikuli library in your project.

  2. Take a screenshot of that area where you want to click and save it in your system with name, perhaps "openButton" for the following example: (Better if small in area size)

  3. Use the Pattern and Screen classes:

    Screen obj = new Screen();
    
    Pattern openButton = new Pattern(filepath + "OpenButton.PNG");
    
    s.click(openButton);
    

See "How to use Sikuli with Selenium" for more information.

Upvotes: 0

Alok Sharma
Alok Sharma

Reputation: 11

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();

Upvotes: 1

alexey.chumagin
alexey.chumagin

Reputation: 630

Try

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

Upvotes: 3

Related Questions