A web element is seemingly clicked but in fact no action is performed (Android)

Finally , after many tries , some1 has suggested me to work with jquery.
after some digging , I’ve used executeScript with jquery’s tap , and it worked…

$('#btn_login_button').trigger('tap');

I was wondering all other methods with click and element’s coordinates didn’t work

2 Likes

I am having the same problem, is it possible to do this using ruby and appium?

Can a jquery command be passed in? eg. driver.execute_script

@Paul_Anderson - I think it might be achieved by ruby as well , eventually you are using the same appium’s api in both cases …

good luck

Do you know what the full syntax would be for such a command?

I have found a way to click the web element - using adb shell input tap 700 190

Would prefer to use an inbuilt method however it does not work using drivers.execute_script(‘mobile: tap’, x: 700, y: 190)

Hello

I Have found a reason WHY this is happening…
The resolution of web view and native view sometimes is different.
So when we try “element.click()” it remembers the position (X,Y) in WEBVIEW and tryes to click on that position in NATIVE view (It does not matter if you are currently in web view). That’s why we get a “positive” click in console.

What we need is a method that will get location of an element by X,Y in web view and transform it in to native view location with X,Y.

Hi kirill
I am also facing same issue

so I tried solution given by you
JavascriptExecutor js = (JavascriptExecutor) driver;
Point location = logOut.getLocation();
Dimension size = logOut.getSize();
double x = location.getX() + size.getWidth() / 2.0;
double y = location.getY() + size.getHeight() / 2.0;
HashMap<String, Double> point = new HashMap<String, Double>();
point.put(“x”, x);
point.put(“y”, y);
js.executeScript(“mobile: tap”, point);

I am getting The coordinates provided to an interactions operation are invalid error message

Please let me know where I am doing wrong
My application is pure Native application

My “fake” successful click was caused by different size in native and web view (common problem)

So to solve it we should get a “difference” value. (how much bigger/smaller is native/web view)

I have static parameters:

    private static double nativeX;    
    private static double nativeY;
    private static double coeffX;
    private static double coeffY;

To set them i use this method…

public void setCoeffs() {
switchToNativeWindow();
if (driver.findElement(By.xpath(“//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]”)).isDisplayed()) {
topDeviceBarSize = driver.findElement(By.xpath(“//android.widget.LinearLayout[1]/android.widget.FrameLayout[1]”))
.getLocation().getY();
}
nativeX = driver.manage().window().getSize().getWidth();
nativeY = (driver.manage().window().getSize().getHeight())-topDeviceBarSize;
switchToWebWindow();
double webX = driver.findElement(By.xpath(“//body”)).getSize().getWidth();
double webY = driver.findElement(By.xpath(“//body”)).getSize().getHeight();
coeffX = nativeX/webX;
coeffY = nativeY/webY;
System.out.println(“extention is set”);
}

When we know the “coeff” parameters we can click on elements:

public void tapOnElement(WebElement element) {
waitForPageToLoad(driver);
switchToWebWindow();
int coordinateX = doubleToIntegerWithRounding((element.getLocation().getX()*coeffX)
+ (((element.getSize().width)*coeffX) / 2));
int coordinateY = doubleToIntegerWithRounding((element.getLocation().getY()*coeffY)
+ topDeviceBarSize + (((element.getSize().height)*coeffY) / 2));
// if (coordinateY >= nativeY){ //we need this is the element is out of sight
// coordinateY = scrollDown(element);
// }
System.out.println(“@@@ Clicking on Element " + element);
switchToNativeWindow();
driver.tap(1, coordinateX, coordinateY, 1);
System.out.println(”@@@ With coordinates " + coordinateX + " " + coordinateY);
switchToWebWindow();
}

for any questions: [email protected]

I have a similar problem except I’m emulating iOS. I think the button not working has to do with when I go to the inspector, it lists it as UIAStaticText instead of something like Button or UIAButton. What confuses me is I can’t seem to switch to a WebView Context (unless UIA prefix class/tag name means you’re in the Webview?). When I select it from the inspector, even after it refreshes, I see no change from when I first loaded the inspector. When I set the context as Webview_1 from the test script, then open the inspector, all I see is a screenshot of my first view of the app with no elements I can click on or expand on.

Thankyou
This is working for me
Please help me to choose image from gallery in android

Hi @kirill,
This approach - switch to native context and perform action on element - is invalid in case of iOS and Android.
In my case I am trying to automate an application which is a hybrid app and starting Appium driver in WEBVIEW context to perform actions as I don’t need to define different elements for iOS and Android platform.
But in above case you explained to switch context to native may require two different elements for same action in iOA and android.

Please help.
Thanks.

How can I execute above JQuery in my java-selenium code?
Please help.

You should try next :

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(**HERE GOES YOUR SCRIPT**);

Good luck

Even I am also facing same issue could any one please help on this.I am trying to click on an element in webview, element is clicking but no action was performing. Basically it is Hybrid Application. Is there any changes required while generating Apk using cordova for Webview actions.

Thank you.

Read the concepts of Context Switches, driver simply cant work in single context.

I have Switched to Webview using driver.context(webview);

You can ask the developer who built the app, I do believe that the click event is not handled. May be in the code, we use touchstart for that element (work for mobile).

Please use tap function as a workaround.

I also tried with javaScript but it worked intermittently. Finally, I used tap on location (co-ordinate) instead.

Hi thanks for the update, how developer can handle this in code basically they are building hybrid application using cordova

From my point of view, We shouldn’t require to change product code to maximize automation test coverage. Test the product as it is.

Just ask them to make sure that the code doesn’t handle click event and choose another correct approach for current Automation testing.

Hi, Finally I am able to click on some elements in Webview and Action is also performing