title: How to find the coordinates of the buttons on a canvas, and click on them after using Java and Selenium?
body: <p>I have an online calculator that i want to automate some operations for, like subtraction, division, etc. but the thing is that there are no elements since it is a canvas app calculator (link below). I'm wondering how can i click the buttons so im able to automate some operations?</p>
  
  <p><strong>The online calculator im trying to automate:</strong> </p>
  
  <p><a href="https://www.online-calculator.com/full-screen-calculator/" rel="nofollow noreferrer">https://www.online-calculator.com/full-screen-calculator/</a></p>
  
  <p><strong>The canvas HTML code</strong></p>
  
  <p><code>&lt;canvas id="canvas" width="335" height="434" style="position: absolute; display: block; background-color: rgb(255, 255, 255); width: 167.939px; height: 217px;"&gt;&lt;/canvas&gt;</code></p>
  
  <p><strong>My Selenium-Java code</strong></p>
  
  <pre><code>driver.get("https://www.online-calculator.com/full-screen-calculator/");
  driver.manage().window().maximize();        
  WebElement li = driver.findElements(By.tagName("iframe")).get(0);
  driver.switchTo().frame(li);        
  WebElement canv = driver.findElements(By.tagName("canvas")).get(0);
  System.out.println(canv.getSize());
  System.out.println(canv.getLocation());
  
  try {
   Actions builder = new Actions(driver);
   builder.moveToElement(canv, x, y);
   builder.click();
   builder.perform();
      } catch (Exception e) 
      {
        // do nothing
      }
  </code></pre>
  
  <p>So as you see in above code, I still have to find the x and y of the operations i want to run. For ex, how can i find the coordinates of the buttons 10, 4 and the subtraction operation '-', if I want to calculate '10 - 4' and then validate that it is equal to 6. Any help would be highly appreciated. Thanks :)</p>
  
  <p><strong>Note:</strong> The canvas width, height and location will change if the window size changes ((Im thinking later of locking the window size so my tests are not flaky on different screens)).</p>