question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Click failed at coordinates - InvalidElementStateException

See original GitHub issue

The problem

I’m trying to click coordinates of a button after entering text. This results in org.openqa.selenium.InvalidElementStateException: Click failed at (362, 322) coordinates even though I’m not using any element here, just clicking X, Y on the screen. It works on 2 of my devices (both with high-resolution screens), doesn’t work on one device, which is Xiaomi Redmi 4X. I’m planning to roll out my tests to a large number of devices in a device farm, so a problem like this can be serious. Note that it’s not the first click on this device that fails, multiple clicks before that one work fine.

Environment

  • Appium version (or git revision) that exhibits the issue: 1.17.1
  • Last Appium version that did not exhibit the issue (if applicable): N/A
  • Desktop OS/version used to run Appium: macOS 10.15.5 Catalina
  • Node.js version (unless using Appium.app|exe): 14.2.0
  • Mobile platform/version under test: Android 7.1.2
  • Real device or emulator/simulator: Real device
  • Appium CLI or Appium.app|exe: CLI

Details

The device is Xiaomi Redmi 4X. The flow of the test is as follows:

  • Open the app and wait for it to load
  • Click the e-mail field, enter text
  • Click the continue button <- this is the step that is failing.

I checked and at the time I’m trying to click coordinates, driver returns the resolution as 720x1280, so the coordinates are well within that.

It’s a Unity app, so I’m using image recognition to locate the elements. That’s why I need to use coordinates to click them (which are coordinates of the centre of the images found).

Is there a workaround?

Link to Appium logs

https://gist.github.com/dariuszteooh/a21e3a56ea7491860309ed373379cbf4

Code To Reproduce Issue [ Good To Have ]

public void tapCoordinates(int x, int y) {
        PointOption pointOption = new PointOption().withCoordinates(x, y);
        new TouchAction<>(driver).tap(pointOption).perform();
    }

Tried also:

public void tapCoordinates(int x, int y) {
        PointOption pointOption = new PointOption().withCoordinates(x, y);
       TouchAction action = new TouchAction(driver);
        action.press(pointOption).release().perform();
    }

Same result. Thanks in advance.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
dariuszteoohcommented, Jun 11, 2020

Managed to find a workaround for this. So for anyone that’s struggling with the same, I’ll post the solution here. This is caused by the Unity keyboard being used to send keys. If you dismiss the keyboard by clicking the little OK button in the text field, everything works fine. If you dismiss it with any other way (clicking outside, clicking back button, clicking enter), the next click will cause the error I mention in the original post. Luckily, the button is possible to locate through XPath. Code: WebElement okButton = driver.findElementByXPath("//android.widget.Button[@text='OK']"); if (okButton.isDisplayed()) { okButton.click(); }

Hope this helps someone.

0reactions
mykola-mokhnachcommented, Jun 11, 2020

Closed as third party issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Click failed at (x, y) coordinates, though the ... - GitHub
The problem When trying to perform a tap by coordinates, i get the following exception: org.openqa.selenium.InvalidElementStateException: ...
Read more >
InvalidElementStateException while doing send_key or clear()
When this site is opened "Accept cookies" pop-up appears, so you have first to close it. This element is inside an iframe.
Read more >
Cannot tap an element: Tap at [x=540.5, y=2048.0] has failed
Hello, I have problem with tapping an element in android application. In appium inspector it seems that the link is outside of form...
Read more >
Use org.openqa.selenium.InvalidElementStateException in ...
The code snippet trying to find an element and then clicking on it. if the coordinates are not correct then it throws InvalidElementStateException....
Read more >
How to Use Touch Actions in Appium: Swipe Tap Touch
Press by using an element and duration (in seconds); Press by using x,y coordinates, and duration (in seconds); Horizontal swipe by using the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found