0

I used below code with multiple points but still its not even drawing a dot on canvas. It is not even recognizing the element. Any other options to automate?

WebElement element = driver.findElement(By.xpath("xpath of canvas"));
Actions builder = new Actions(driver);
Action drawAction = builder.moveToElement(element,135,15) //start points x axis and y axis. 
 .click()
 .moveByOffset(200, 60) // 2nd points (x1,y1)
 .click()
 .moveByOffset(100, 70)// 3rd points (x2,y2)
 .doubleClick()
 .build();
drawAction.perform();
Kate Paulk
31.5k8 gold badges56 silver badges109 bronze badges
asked Mar 24, 2020 at 12:22
8
  • 1
    What error are you getting? If the element is not being found, you may need a different XPath. Can you update your answer to add the HTML code and your XPath, so we have enough information to help you? Commented Mar 24, 2020 at 12:52
  • It just ignores that field not even writing a dot there. Also, no error is thrown. Xpath is "//canvas['signature']". Commented Mar 24, 2020 at 13:08
  • Please update your question and include the html that you're working with. Another thing you can try is to log the properties of the element. That will help to tell you if you've got the addressing correct. Commented Mar 24, 2020 at 13:34
  • Please update the error you are getting . this looks like xpath issue check your xpath Commented Mar 24, 2020 at 14:32
  • Have you seen sqa.stackexchange.com/questions/42846/… ? This feels like a duplicate question. Commented Mar 24, 2020 at 16:02

1 Answer 1

1

Use click and hold instead of click, the click will just click the mouse and releases it suddenly.

The below code is an example:

 System.setProperty("webdriver.chrome.driver","c:/chromedriver.exe");
 WebDriver driver = new ChromeDriver();
 driver.manage().window().maximize();
 driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS) ;
 driver.get("http://apps.zetakey.com/signsend/");
 Actions builder = new Actions(driver);
 Action drawAction = builder.moveToElement(driver.findElement(By.cssSelector("[id='newSignature']"))) //start points x axis and y axis. 
 .clickAndHold()
 .moveByOffset(-50, 60) // 2nd points (x1,y1)
 .moveByOffset(-60, -70)// 3rd points (x2,y2)
 .moveByOffset(150, 60) // 2nd points (x1,y1)
 .moveByOffset(-60, -70)// 3rd points (x2,y
 .doubleClick()
 .build();
 drawAction.perform();
 Thread.sleep(6000);

Read more about action class at :

https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/interactions/Actions.html

answered Mar 27, 2020 at 23:32
3
  • Click and Hold also did not work. I presume, it is something to do with development team exposing elements. Commented Apr 1, 2020 at 12:54
  • @User58 your offset is calculated from the top left corner , so try using smaller number like 10,10 instead of 200 to make sure if it's working or not Commented Apr 1, 2020 at 13:16
  • Top left of canvas element , not the entire Page Commented Apr 1, 2020 at 14:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.