0

I am working on assignment where there are no locator available to locate elements. I am trying to perform Subtraction functionality of a Online Calculator.

URL: https://www.online-calculator.com/full-screen-calculator/

I have tried below code so far:

    WebDriver driver;
    System.setProperty("webdriver.chrome.driver", "F:\\Al_Driver\\chromedriver.exe");
    driver = new ChromeDriver();
    driver.get("https://www.online-calculator.com/full-screen-calculator/");
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

    Robot r = new Robot();
    r.keyPress(KeyEvent.VK_8);
    r.keyRelease(KeyEvent.VK_8);

    r.keyPress(KeyEvent.VK_SUBTRACT);
    r.keyRelease(KeyEvent.VK_SUBTRACT);

    r.keyPress(KeyEvent.VK_5);
    r.keyRelease(KeyEvent.VK_5);

    r.keyPress(KeyEvent.VK_EQUALS);
    r.keyRelease(KeyEvent.VK_EQUALS);

    driver.close();

Only thing in the above code is that i am unable to perform assertion using selenium. Also i am hardcoding values in the script. Is there any way to find the elements of the given URL or any other way to perform the same?? Any help will be appreciated.Thanks in Advance

Ab123
  • 415
  • 2
  • 13
  • 34

1 Answers1

0

This is a canvas object and you can automate in selenium by clicking on coordinates. Download a Chrome plugin to find the coordinates of the image elements that you want to click. Then use Actions class methods like moveByOffset(xcord,ycord) to perform the click operations.

ashwinin
  • 81
  • 5
  • The issue of Finding elements has been resolved here because i have used Robot class, So i am inserting directly through Keyboard. I am just trying to Assert the result, and since it result will come into Image. I will not be able to perform the same. – Ab123 Feb 24 '20 at 17:53
  • you can talk to the developer to get the canvas object and retrieve data using the handler. It is a complex process, but definitely possible. – ashwinin Feb 25 '20 at 10:37