Not able to find elements using any locators for my mobile app


#1

Hello ,

I am not able find elements of my mobile app either from ID,X-PATH or classname

getting below exception

attached screenshot of code and app elements

please help in resolving the same

thanks in advance

Exception in thread “main” org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters.

For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html

Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:48’

System info: host: ‘AGI-LT-915’, ip: ‘192.168.187.122’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_201’

Driver info: io.appium.java_client.android.AndroidDriver

Capabilities {app: D:\selenium\Workspace\eCOA…, appActivity: cordova.LSeCOA.Production.M…, appPackage: cordova.LSeCOA.Production, appWaitActivity: cordova.LSeCOA.Production.M…, appWaitPackage: cordova.LSeCOA.Production, databaseEnabled: false, desired: {app: D:\selenium\Workspace\eCOA…, deviceName: EDC, platformName: android}, deviceManufacturer: Google, deviceModel: Android SDK built for x86, deviceName: emulator-5554, deviceScreenSize: 1080x1920, deviceUDID: emulator-5554, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, platform: LINUX, platformName: Android, platformVersion: 8.1.0, takesScreenshot: true, warnings: {}, webStorageEnabled: false}

Session ID: 91b562da-f9aa-4cab-b6c5-9a69eeda88c6

*** Element info: {Using=id, value=serviceUrl}

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

at java.lang.reflect.Constructor.newInstance(Unknown Source)

at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)

at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)

at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)

at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)

at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)

at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)

at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)

at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)

at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)

at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)

at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:62)

at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)

at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)

at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:372)

at io.appium.java_client.DefaultGenericMobileDriver.findElementById(DefaultGenericMobileDriver.java:70)

at io.appium.java_client.AppiumDriver.findElementById(AppiumDriver.java:1)

at io.appium.java_client.android.AndroidDriver.findElementById(AndroidDriver.java:1)

at eCOA.login.main(login.java:17)


#2

Keep some delay before sending the keys. Not sure is the app Open opened before sending the keys. So add some delay and then send keys.


#3

Issue is not about delay, when i fetch the page source using ‘driver.getPageSource()’ i can see no clickable element in the page, yet there is URL text box and login page in the mobile app, and in mobile app i can enter URL and click on login button, but how to do it from appium automation ?


#4

Hi,
Please try to locate the elements from Appium Inspector. If you are able to locate elements through Appium inspector then your problem is solved.
Incase if your are unable to locate your app elements in Appium inspector, then check the app if it has a web-view or not (Might be hybrid app)?

Follow the below steps to figure out whether the app is loaded with webview or not.
This code should run after loading your app. (App should be in foreground - so that it will fetch all context names)

	    Set<String> contextSet = androidDriver.getContextHandles();
    		for(String contextName: contextSet) {
    			System.out.println("context Name " + contextName);
    			androidDriver.context(contextName); //Changing the context
    		}

#5

Yes it is an hybrid app, i am able to locate elements in emulator by switching context, but when i connect the real andriod device i am not able to locate elements

will webview context works with real device ?


#6

Yes Webveiw switching works on real devices too.