Monty
Monty

Reputation: 5

Webdriver Click not working for chrome on Android devices

I am trying to automate a web application on android device using Selenium webdriver and appium. However am stuck because click() seems to be not working for chrome browser on Android devices, same works for chrome browser on desktop.

Please see attached test code to reproduce the issue on gmail.com and also appium console logs. Not sure if this an issue with chromeDriver or needs to implemented some other way.

Code

import java.net.MalformedURLException;
import java.net.URL;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class TestMobileBrowser {

    public DesiredCapabilities capabilities;
    public RemoteWebDriver driver;

@BeforeTest
public void beforeTest() throws MalformedURLException{
    capabilities = new DesiredCapabilities();
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("deviceName", "Android");
    capabilities.setCapability("browserName", "chrome");
    capabilities.setCapability("newCommandTimeout", 60);
    driver = new RemoteWebDriver(new URL("http://localhost:4723/wd/hub"), capabilities);    
}

@Test
public void test(){
    driver.get("http://gmail.com");
    driver.findElement(By.id("Email")).sendKeys("test");
    driver.findElement(By.id("next")).click();  
    driver.findElement(By.id("Passwd")).sendKeys("test");
    driver.findElement(By.id("signIn")).click();    
}

}

Appium logs

> info: --> POST /wd/hub/session {"desiredCapabilities":{"newCommandTimeout":60,"browserName":"chrome","platformName":"Android","deviceName":"Android"}}
> info: Client User-Agent string: Apache-HttpClient/4.5.1 (Java/1.8.0_60)
> info: Set mode: Proxying straight through to Chromedriver
> info: [debug] Looks like we want chrome on android
> info: [debug] Creating new appium session b061da72-cfb4-4d06-8595-b9fe52439d37
> info: [debug] Checking whether adb is present
> info: [debug] Using adb from D:\eGain\Automation\Android\sdk\platform-tools\adb.exe
> info: [debug] Using fast reset? true
> info: [debug] Preparing device for session
> info: [debug] Not checking whether app is present since we are assuming it's already on the device
> info: Retrieving device
> info: [debug] Trying to find a connected android device
> info: [debug] Getting connected devices...
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe devices
> info: [debug] 1 device(s) connected
> info: Found device a33124a7
> info: [debug] Setting device id to a33124a7
> info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 wait-for-device
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 shell "echo 'ready'"
> info: [debug] Starting logcat capture
> info: [debug] Pushing unlock helper app to device...
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 install "C:\Program Files (x86)\Appium\node_modules\appium\build\unlock_apk\unlock_apk-debug.apk"
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 shell "dumpsys window"
> info: Unlocking screen
> info: [debug] Screen is locked, trying to unlock
> info: [debug] Getting device API level
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 shell "getprop ro.build.version.sdk"
> info: [debug] Device is at API Level 23
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 shell "am start -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000 -n io.appium.unlock/.Unlock"
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 shell "dumpsys window"
> info: [debug] Screen is unlocked, continuing
> info: [debug] Forwarding system:4724 to device:4724
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 forward tcp:4724 tcp:4724
> info: [debug] Pushing appium bootstrap to device...
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 push "C:\\Program Files (x86)\\Appium\\node_modules\\appium\\build\\android_bootstrap\\AppiumBootstrap.jar" /data/local/tmp/
> info: Starting App
> info: [debug] Attempting to kill all 'uiautomator' processes
> info: [debug] Getting all processes with 'uiautomator'
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 shell "ps 'uiautomator'"
> info: [debug] No matching processes found
> info: [debug] Running bootstrap
> info: [debug] spawning: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 shell uiautomator runtest AppiumBootstrap.jar -c io.appium.android.bootstrap.Bootstrap -e pkg com.android.chrome -e disableAndroidWatchers false
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
> info: [debug] [UIAUTOMATOR STDOUT] io.appium.android.bootstrap.Bootstrap:
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 1
> info: [debug] [BOOTSTRAP] [debug] Socket opened on port 4724
> info: [debug] [BOOTSTRAP] [debug] Appium Socket Server Ready
> info: [debug] [BOOTSTRAP] [debug] Loading json...
> info: [debug] [BOOTSTRAP] [debug] Registered crash watchers.
> info: [debug] Pushing command to appium work queue: ["getDataDir",{}]
> info: [debug] [BOOTSTRAP] [debug] Client connected
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"getDataDir","params":{}}
> info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
> info: [debug] [BOOTSTRAP] [debug] Got command action: getDataDir
> info: [debug] dataDir set to: /data/local/tmp
> info: Chromedriver: Changed state to 'starting'
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":"\/data\/local\/tmp"}
> info: Chromedriver: Set chromedriver binary as: C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe
> info: Chromedriver: Killing any old chromedrivers, running: FOR /F "usebackq tokens=5" %a in (`netstat -nao ^| findstr /R /C:"9515 "`) do (FOR /F "usebackq" %b in (`TASKLIST /FI "PID eq %a" ^| findstr /I chromedriver.exe`) do (IF NOT %b=="" TASKKILL /F /PID %a))
> info: Chromedriver: No old chromedrivers seemed to exist
> info: Chromedriver: Spawning chromedriver with: C:\Program Files (x86)\Appium\node_modules\appium\node_modules\appium-chromedriver\chromedriver\win\chromedriver.exe --url-base=wd/hub --port=9515
> info: Chromedriver: [STDOUT] Starting ChromeDriver 2.23.409699 (49b0fa931cda1caad0ae15b7d1b68004acd05129) on port 9515
> Only local connections are allowed.
> info: JSONWP Proxy: Proxying [GET /status] to [GET http://127.0.0.1:9515/wd/hub/status] with no body
> info: JSONWP Proxy: Got response with status 200: "{\"sessionId\":\"\",\"status\":0,\"value\":{\"build\":{\"version\":\"alpha\"},\"os\":{\"arch\":\"x86_64\",\"name\":\"Windows NT\",\"version\":\"10.0.10586\"}}}"
> info: JSONWP Proxy: Proxying [POST /session] to [POST http://127.0.0.1:9515/wd/hub/session] with body: {"desiredCapabilities":{"chromeOptions":{"androidPackage":"com.android.chrome","androidDeviceSerial":"a33124a7"}}}
> info: JSONWP Proxy: Got response with status 200: {"sessionId":"0ebf4514a9760982649f45ce431656e8","status":0,"value":{"acceptSslCerts":true,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{"chromedr...
> info: Chromedriver: Changed state to 'online'
> info: [debug] Overriding session id with "0ebf4514a9760982649f45ce431656e8"
> info: [debug] Device launched! Ready for commands
> info: [debug] Setting command timeout to 60 secs
> info: [debug] Appium session started with sessionId 0ebf4514a9760982649f45ce431656e8
> info: <-- POST /wd/hub/session 303 18667.504 ms - 70 
> info: --> GET /wd/hub/session/0ebf4514a9760982649f45ce431656e8 {}
> info: JSONWP Proxy: Proxying [GET /wd/hub/session/0ebf4514a9760982649f45ce431656e8] to [GET http://127.0.0.1:9515/wd/hub/session/0ebf4514a9760982649f45ce431656e8] with body: {}
> info: JSONWP Proxy: Got response with status 200: {"sessionId":"0ebf4514a9760982649f45ce431656e8","status":0,"value":{"acceptSslCerts":true,"applicationCacheEnabled":false,"browserConnectionEnabled":false,"browserName":"chrome","chrome":{"chromedr...
> info: JSONWP Proxy: Replacing sessionId 0ebf4514a9760982649f45ce431656e8 with 0ebf4514a9760982649f45ce431656e8
> info: <-- GET /wd/hub/session/0ebf4514a9760982649f45ce431656e8 200 11.638 ms - 606 
> info: --> POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/url {"url":"http://gmail.com"}
> info: JSONWP Proxy: Proxying [POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/url] to [POST http://127.0.0.1:9515/wd/hub/session/0ebf4514a9760982649f45ce431656e8/url] with body: {"url":"http://gmail.com"}
> info: JSONWP Proxy: Got response with status 200: {"sessionId":"0ebf4514a9760982649f45ce431656e8","status":0,"value":null}
> info: JSONWP Proxy: Replacing sessionId 0ebf4514a9760982649f45ce431656e8 with 0ebf4514a9760982649f45ce431656e8
> info: <-- POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/url 200 2374.402 ms - 72 
> info: --> POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element {"using":"id","value":"Email"}
> info: JSONWP Proxy: Proxying [POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element] to [POST http://127.0.0.1:9515/wd/hub/session/0ebf4514a9760982649f45ce431656e8/element] with body: {"using":"id","value":"Email"}
> info: JSONWP Proxy: Got response with status 200: {"sessionId":"0ebf4514a9760982649f45ce431656e8","status":0,"value":{"ELEMENT":"0.46630814854548563-1"}}
> info: JSONWP Proxy: Replacing sessionId 0ebf4514a9760982649f45ce431656e8 with 0ebf4514a9760982649f45ce431656e8
> info: <-- POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element 200 154.429 ms - 103 
> info: --> POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element/0.46630814854548563-1/value {"id":"0.46630814854548563-1","value":["test"]}
> info: JSONWP Proxy: Proxying [POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element/0.46630814854548563-1/value] to [POST http://127.0.0.1:9515/wd/hub/session/0ebf4514a9760982649f45ce431656e8/element/0.46630814854548563-1/value] with body: {"id":"0.46630814854548563-1","value":["test"]}
> info: JSONWP Proxy: Got response with status 200: {"sessionId":"0ebf4514a9760982649f45ce431656e8","status":0,"value":null}
> info: JSONWP Proxy: Replacing sessionId 0ebf4514a9760982649f45ce431656e8 with 0ebf4514a9760982649f45ce431656e8
> info: <-- POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element/0.46630814854548563-1/value 200 300.313 ms - 72 
> info: --> POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element {"using":"id","value":"next"}
> info: JSONWP Proxy: Proxying [POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element] to [POST http://127.0.0.1:9515/wd/hub/session/0ebf4514a9760982649f45ce431656e8/element] with body: {"using":"id","value":"next"}
> info: JSONWP Proxy: Got response with status 200: {"sessionId":"0ebf4514a9760982649f45ce431656e8","status":0,"value":{"ELEMENT":"0.46630814854548563-2"}}
> info: JSONWP Proxy: Replacing sessionId 0ebf4514a9760982649f45ce431656e8 with 0ebf4514a9760982649f45ce431656e8
> info: <-- POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element 200 160.963 ms - 103 
> info: --> POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element/0.46630814854548563-2/click {"id":"0.46630814854548563-2"}
> info: JSONWP Proxy: Proxying [POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element/0.46630814854548563-2/click] to [POST http://127.0.0.1:9515/wd/hub/session/0ebf4514a9760982649f45ce431656e8/element/0.46630814854548563-2/click] with body: {"id":"0.46630814854548563-2"}
> info: JSONWP Proxy: Got response with status 200: {"sessionId":"0ebf4514a9760982649f45ce431656e8","status":0,"value":null}
> info: JSONWP Proxy: Replacing sessionId 0ebf4514a9760982649f45ce431656e8 with 0ebf4514a9760982649f45ce431656e8
> info: <-- POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element/0.46630814854548563-2/click 200 350.330 ms - 72 
> info: --> POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element {"using":"id","value":"Passwd"}
> info: JSONWP Proxy: Proxying [POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element] to [POST http://127.0.0.1:9515/wd/hub/session/0ebf4514a9760982649f45ce431656e8/element] with body: {"using":"id","value":"Passwd"}
> info: JSONWP Proxy: Got response with status 200: {"sessionId":"0ebf4514a9760982649f45ce431656e8","status":7,"value":{"message":"no such element: Unable to locate element: {\"method\":\"id\",\"selector\":\"Passwd\"}\n  (Session info: chrome=52.0.2...
> info: JSONWP Proxy: Replacing sessionId 0ebf4514a9760982649f45ce431656e8 with 0ebf4514a9760982649f45ce431656e8
> info: <-- POST /wd/hub/session/0ebf4514a9760982649f45ce431656e8/element 200 227.600 ms - 331 
> info: [debug] Didn't get a new command in 60 secs, shutting down...
> info: Shutting down appium session
> info: Chromedriver: Changed state to 'stopping'
> info: JSONWP Proxy: Proxying [DELETE /] to [DELETE http://127.0.0.1:9515/wd/hub/session/0ebf4514a9760982649f45ce431656e8] with no body
> info: JSONWP Proxy: Got response with status 200: "{\"sessionId\":\"0ebf4514a9760982649f45ce431656e8\",\"status\":0,\"value\":null}"
> info: Chromedriver: Changed state to 'stopped'
> info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"shutdown"}
> info: [debug] [BOOTSTRAP] [debug] Got command of type SHUTDOWN
> info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":"OK, shutting down"}
> info: [debug] [BOOTSTRAP] [debug] Closed client connection
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: numtests=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=.
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: id=UiAutomatorTestRunner
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: test=testRunServer
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: class=io.appium.android.bootstrap.Bootstrap
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: current=1
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: 0
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS: stream=
> info: [debug] [UIAUTOMATOR STDOUT] Test results for WatcherResultPrinter=.
> info: [debug] [UIAUTOMATOR STDOUT] Time: 76.13
> info: [debug] [UIAUTOMATOR STDOUT] OK (1 test)
> info: [debug] [UIAUTOMATOR STDOUT] INSTRUMENTATION_STATUS_CODE: -1
> info: [debug] Sent shutdown command, waiting for UiAutomator to stop...
> info: [debug] UiAutomator shut down normally
> info: [debug] executing cmd: D:\eGain\Automation\Android\sdk\platform-tools\adb.exe -s a33124a7 shell "am force-stop com.android.chrome"
> info: [debug] Stopping logcat capture
> info: [debug] Logcat terminated with code null, signal SIGTERM
> info: [debug] Cleaning up appium session
> info: [debug] We shut down because no new commands came in

Upvotes: 0

Views: 2117

Answers (4)

Sumit Shitole
Sumit Shitole

Reputation: 130

driver = new RemoteWebDriver(new URL("http://localhost:4723/wd/hub"), capabilities); This line might be cause of error. In other answers AndroidDriver and appium driver is used. Some of methods of these drivers may not be available in RemoteWebDriver

Upvotes: 0

Venkatesh G
Venkatesh G

Reputation: 9556

The following code is working for me

Here is the code

public class TestMobileBrowser {

public DesiredCapabilities capabilities;
public AppiumDriver driver;
@BeforeTest
public void beforeTest() throws Exception{

capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Android");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Chrome");
capabilities.setCapability("platformVersion", "5.0.2");
capabilities.setCapability("appPackage", "com.android.chrome");
capabilities.setCapability("appActivity","com.google.android.apps.chrome.ChromeTabbedActivity");
driver= new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}

@Test
public void test(){
driver.get("http://gmail.com");
driver.findElement(By.id("Email")).sendKeys("test");
Thread.sleep(30000);
driver.findElement(By.id("next")).click();  
driver.findElement(By.id("Passwd")).sendKeys("test");
driver.findElement(By.id("signIn")).click();    
}

}

Upvotes: 2

Suman
Suman

Reputation: 436

@Vaibhav because there is screen transition between ID and password field entry and appium starts looking for password field before the next screen is displayed so I would suggest you to add a wait condition for it.

WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//android.widget.EditText[@resource-id='Passwd']")));

The below capabilities worked for me -

public void setUp() throws Exception {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Galaxy");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability(CapabilityType.BROWSER_NAME, "Chrome");
capabilities.setCapability("platformVersion", "6.0");
capabilities.setCapability("appPackage", "com.android.chrome");
capabilities.setCapability("appActivity","com.google.android.apps.chrome.ChromeTabbedActivity");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

}

But if you are able to enter gmail user name and click on "next" button using your capabilities then you can use your existing capabilities. Just add wait statement before clicking password.

Upvotes: 2

Suman
Suman

Reputation: 436

capabilities.setCapability("deviceName", "YOUR-DEVICE-NAME"); // such as GalaxyS6
capabilities.setCapability("browserName", "Chrome"); // its Chrome instead of chrome

You might need to add : chromedriverExecutable under capabilities. The absolute local path to webdriver executable (if Chromium embedder provides its own webdriver, it should be used instead of original chromedriver bundled with Appium)

It is unable to find password field.If its hidden by device keyboard, I would suggest to hide keyboard first.

driver.hideKeyboard();
driver.findElement(By.id("Passwd")).sendKeys("test");

Upvotes: 0

Related Questions