I am using selenium and appium to automate mobile chrome browser on Android phone. I have connected real android device through
adb connect {ip address of mobile}
All other test cases on android chrome browser on a real device are running successfully. But for the image upload, the browser is crashing.
I am using below code for uploading image
public class UploadPhotoPage extends TestBase {
// Page Factory Object Repository
@FindBy(id = "file-upload")
WebElement fileUpload;
// Initialising the page object
public UploadPhotoPage() {
PageFactory.initElements(driver, this);
}
// Actions
public void uploadphotos(String imagePath) throws AWTException, InterruptedException {
fileUpload.sendKeys(imagePath);
}
}
Image path is on windows machine where appium server and eclipse are executing test cases.
What is wrong here?
Error log on appium server:
[W3C] Driver proxy active, passing request on via HTTP proxy [JSONWP Proxy] Matched '/wd/hub/session/34e405a5-1bad-4711-9e1c-956e2d7391f6/element/0.6272871137575717-18/text' to command name 'getText' [JSONWP Proxy] Proxying [GET /wd/hub/session/34e405a5-1bad-4711-9e1c-956e2d7391f6/element/0.6272871137575717-18/text] to [GET http://127.0.0.1:8003/wd/hub/session/adb1415c77099095355e619b36dc5e1e/element/0.6272871137575717-18/text] with body: {} [JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"adb1415c77099095355e619b36dc5e1e\",\"status\":10,\"value\":{\"message\":\"stale element reference: element is not attached to the page document\n (Session info: chrome=70.0.3538.64)\n (Driver info: chromedriver=2.42.591088 (7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT 6.1.7601 SP1 x86_64)\"}}" [W3C] Encountered internal error running command: ProxyRequestError: Could not proxy command to remote server. Original error: The request to /wd/hub/session/34e405a5-1bad-4711-9e1c-956e2d7391f6/element/0.6272871137575717-18/text has failed [W3C] at JWProxy.proxy$ (C:\Users\chintamanim\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\jsonwp-proxy\proxy.js:182:13) [W3C] at tryCatch (C:\Users\chints\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40) [W3C] at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\chints\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22) [W3C] at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (C:\Users\chints\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21) [W3C] at GeneratorFunctionPrototype.invoke (C:\Users\chints\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37) [W3C] at [MJSONWP] Matched JSONWP error code 10 to StaleElementReferenceError [HTTP] <-- GET /wd/hub/session/34e405a5-1bad-4711-9e1c-956e2d7391f6/element/0.6272871137575717-18/text 404 95 ms - 2004 [HTTP] [HTTP] --> GET /wd/hub/session/34e405a5-1bad-4711-9e1c-956e2d7391f6/element/0.6272871137575717-18/text [HTTP] {} [W3C] Driver proxy active, passing request on via HTTP proxy [JSONWP Proxy] Matched '/wd/hub/session/34e405a5-1bad-4711-9e1c-956e2d7391f6/element/0.6272871137575717-18/text' to command name 'getText' [JSONWP Proxy] Proxying [GET /wd/hub/session/34e405a5-1bad-4711-9e1c-956e2d7391f6/element/0.6272871137575717-18/text] to [GET http://127.0.0.1:8003/wd/hub/session/adb1415c77099095355e619b36dc5e1e/element/0.6272871137575717-18/text] with body: {} [JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"adb1415c77099095355e619b36dc5e1e\",\"status\":10,\"value\":{\"message\":\"stale element reference: element is not attached to the page document\n (Session info: chrome=70.0.3538.64)\n (Driver info: chromedriver=2.42.591088 (7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT 6.1.7601 SP1 x86_64)\"}}" [W3C] Encountered internal error running command: ProxyRequestError: Could not proxy command to remote server. Original error: The request to /wd/hub/session/34e405a5-1bad-4711-9e1c-956e2d7391f6/element/0.6272871137575717-18/text has failed [W3C] at JWProxy.proxy$ (C:\Users\chints\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\appium-base-driver\lib\jsonwp-proxy\proxy.js:182:13) [W3C] at tryCatch (C:\Users\chints\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40) [W3C] at GeneratorFunctionPrototype.invoke [as _invoke] (C:\Users\chints\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:315:22) [W3C] at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (C:\Users\chints\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:100:21) [W3C] at GeneratorFunctionPrototype.invoke (C:\Users\chints\AppData\Local\Programs\Appium\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37) [W3C] at [MJSONWP] Matched JSONWP error code 10 to StaleElementReferenceError [HTTP] <-- GET /wd/hub/session/34e405a5-1bad-4711-9e1c-956e2d7391f6/element/0.6272871137575717-18/text 404 135 ms - 2004
Below are the capabilities, I have set
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "ONEPLUS A5010");
capabilities.setCapability("platformVersion", "8.1.0");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("browserName", "Chrome");
capabilities.setCapability("deviceId", "XXX.XX.XX.XXX:5555");
capabilities.setCapability("autoGrantPermissions", true);
The issues with my script are as below 1) Stale element issue is because of another element so it was not the root cause. 2) The image path should be of the mobile image not on the desktop. It was a major issue.