Click failed at coordinates - InvalidElementStateException
See original GitHub issueThe 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:
- Created 3 years ago
- Comments:8
Top GitHub Comments
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.
Closed as third party issue