Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.click() command is not working on android devices #2816

Closed
Kocjan opened this issue Jun 10, 2014 · 4 comments
Closed

.click() command is not working on android devices #2816

Kocjan opened this issue Jun 10, 2014 · 4 comments

Comments

@Kocjan
Copy link

Kocjan commented Jun 10, 2014

Hi All,
I am testing some web application (sencha) on my real devices, and i have problem with .click() function. Script was written in Python, and it works perfectly on iOS simulator, everything is fine, but when i execute it on my Nexus 7 (or some other real android devices), click is not working (tap also is not working). In the Appium log everything is fine, all functions are executed properly, but on real device nothing happens. Also if i manually tap with my finger on the button and open menu, other functions have been executed properly after that (.send_keys(), javascript functions... ) but click not.
I suppose there is some problem with ChromeDriver (because on Safari works correctly) or it is something else? Maybe someone have suggestion?

    from appium import webdriver

    desired_caps = {}
    desired_caps['platformName'] = 'Android'
    desired_caps['platformVersion'] = '4.4'
    desired_caps['deviceName'] = 'Nexus 7'
    desired_caps['browserName'] = 'chrome'
    self.driver = webdriver.Remote('http://0.0.0.0:4723/wd/hub', desired_caps)

if I add:

    desired_caps['app'] = 'chrome'

result is the same.
Also if I set code to use default stock browser the problem still exists.

Appium log:


info: Making http request with opts: {"url":"http://127.0.0.1:9515/wd/hub/session/7cc4a06646183bade599f9e73eb47a1e/element","method":"POST","json":{"using":"css selector","sessionId":"7cc4a06646183bade599f9e73eb47a1e","value":"span[class~='login']"}}

debug: Request received with params: {"using":"css selector","sessionId":"7cc4a06646183bade599f9e73eb47a1e","value":"span[class~='login']"}
debug: Proxying command to 127.0.0.1:9515

debug: Proxied response received with status 200: {"sessionId":"7cc4a06646183bade599f9e73eb47a1e","status":0,"value":{"ELEMENT":"0.6617129035294056-1"}}

POST /wd/hub/session/7cc4a06646183bade599f9e73eb47a1e/element 200 103ms - 124b

debug: Appium request initiated at /wd/hub/session/7cc4a06646183bade599f9e73eb47a1e/element/0.6617129035294056-1/click

info: Making http request with opts: {"url":"http://127.0.0.1:9515/wd/hub/session/7cc4a06646183bade599f9e73eb47a1e/element/0.6617129035294056-1/click","method":"POST","json":{"sessionId":"7cc4a06646183bade599f9e73eb47a1e","id":"0.6617129035294056-1"}}

debug: Request received with params: {"sessionId":"7cc4a06646183bade599f9e73eb47a1e","id":"0.6617129035294056-1"}
debug: Proxying command to 127.0.0.1:9515

debug: Proxied response received with status 200: {"sessionId":"7cc4a06646183bade599f9e73eb47a1e","status":0,"value":null}

POST /wd/hub/session/7cc4a06646183bade599f9e73eb47a1e/element/0.6617129035294056-1/click 200 271ms - 85b

debug: Appium request initiated at /wd/hub/session/7cc4a06646183bade599f9e73eb47a1e/element


Python 2.7, Nexus 7, Appium 1.1.0, Android KitKat

@moizjv moizjv added this to the Appium 1.2 milestone Jun 10, 2014
@jlipps jlipps removed this from the Appium 1.2 milestone Jun 10, 2014
@jlipps
Copy link
Member

jlipps commented Jun 10, 2014

Yes, this would be a ChromeDriver issue. My guess is that your app is listening for a certain event (whether it's 'click' or 'touch') and ChromeDriver is sending the other event, so it looks like nothing's happening. You might try changing the listeners in your app to see if that helps.

@jlipps jlipps closed this as completed Jun 10, 2014
@Ethorsen
Copy link

I'm having the exact same problem with a Sencha 2.4 app on Android 4.4 using Cordova 4.1.2. Clicks on Ext.Button are returning a 200 but nothing happen in the webview. Clicks on textboxes are working fine tho.

Kocjan did you find a fix/workaround?

@Ethorsen
Copy link

Here's my dirty fix in case other people are facing the issue. It is written for scalaTest using the java client. It is consistently working for me.

object Click {
    def onElement(cssSelectorString: String): Unit = {
      Click.onElement(cssSelector(cssSelectorString).webElement)
    }

    def onElement(webElement: WebElement): Unit = {
      if (!isAndroidNative) {
        click on webElement
      } else {

        // Fetch DOM document full size
        val documentWidth = javascript.executeScript("return document.width").toString.toDouble
        val documentHeight = javascript.executeScript("return document.height").toString.toDouble

        // Fetch element center position from the DOM
        val elementLeftCenter = webElement.getLocation.getX + (webElement.getSize.getWidth / 2)
        val elementTopCenter = webElement.getLocation.getY + (webElement.getSize.getHeight / 2)

        // Switch back to NATIVE_APP context
        AndroidContext.toNative

        // Fetch the cordova WebView element
        val androidWebView: WebElement = androidWebDriver.findElementByAndroidUIAutomator("""new UiSelector().classNameMatches("^android\.(.*)\.(.*)View$")""")

        val screenXMultiplier = androidWebView.getSize.getWidth / documentWidth
        val screenYMultiplier = androidWebView.getSize.getHeight / documentHeight

        val tapX = (elementLeftCenter * screenXMultiplier).toInt
        val tapY = (elementTopCenter * screenYMultiplier).toInt + androidWebView.getLocation.getY

        // Send a tap event on the specific button position
        androidWebDriver.tap(1, tapX, tapY, 200)

        // Switch back to webView
        AndroidContext.toWebview
      }
    }
  }

@lock
Copy link

lock bot commented May 1, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators May 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants