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
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.
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
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();
}
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.
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.
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.
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.