AppiumQuery
AppiumQuery

Reputation: 31

Cannot identify elements during runtime using Appium

I am new to appium and Java, so please bear with me.

I am trying to automate an app on an emulator. I am able to inspect the elements under UIAUTOMATORVIEWER, however when i run the code, no element in the page can be identified. The app does open up, but elements cannot be identified.

This is the property of the inspected element: Class: android.widget.Button Content-desc: LOGIN

This is part of the page source during runtime, as you can see the login button is present in the page:

This is the gist of my code:

DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.APP, app.getAbsolutePath());         
cap.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "Google Pixel 2");
cap.setCapability(MobileCapabilityType.BROWSER_NAME,"");
cap.setCapability(MobileCapabilityType.PLATFORM_VERSION, "8.0");
cap.setCapability("automationName", "UiAutomator2");    
cap.setCapability(AndroidMobileCapabilityType.APP_PACKAGE, "com.kruxanalytics.kruxmetrix");
cap.setCapability(AndroidMobileCapabilityType.APP_ACTIVITY, "com.kruxanalytics.kruxmetrix.MainActivity");

I have tried the following find element methods:

driver.findElementByAccessibilityId("LOGIN").click();
driver.findElement(By.xpath("//android.widget.Button[@content-desc='LOGIN']")).click();

Appium log mostly contains this:
[WD Proxy] Got an unexpected response: {"sessionId":"5f7bca9b-2e8b-46a7-9727-53a85e0d6df0","status":7,"value":"An element could not be located on the page using the given search parameters."}
[debug] [MJSONWP] Matched JSONWP error code 7 to NoSuchElementError

Upvotes: 0

Views: 773

Answers (2)

Hazim Hamad
Hazim Hamad

Reputation: 54

I think the application is hybrid so you need to include chromedriverExecutable capability , by identifying the location of the driver that suits the device in the emulator, I also have a problem in running Appium on android 8 so try to target another version and it will work.

Upvotes: 1

Dmitri T
Dmitri T

Reputation: 168002

I doubt that your application is capable of loading immediately, most probably you need to introduce a WebDriverWait in order to query the application for the specified element for a specific time span.

So change this line:

driver.findElementByAccessibilityId("LOGIN").click();

to this:

new WebDriverWait(driver,30)
        .until(ExpectedConditions
                .elementToBeClickable(By.xpath("//android.widget.Button[@content-desc='LOGIN ']")))
        .click();

More information: Explicit wait - Mobile Test Automation with Appium

Upvotes: 0

Related Questions