Unable to perform action on element in native android app

Hi,
I’m new to appium and are unable to interact with element in Login page.

Issue detail:
Unable to interact with element in device and getting below exception:
org.openqa.selenium.TimeoutException: Expected condition failed: ‘By.xpath: /hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[2]/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[2]/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup/android.view.ViewGroup[2]/android.view.ViewGroup/android.view.ViewGroup/android.widget.EditText’ locator is not visible. (tried for 10 second(s) with 1000 milliseconds interval)

Please do note, I’m using absolute xpath for interacting with element (meantime, i’ve requested dev team to introduce unique locators). I fetched xpath using latest version of Appium Desktop.

PFB the details:

  • Application built using React Native
  • Appium version: 1.16.0
  • Android version: 10.3.3 (OnePlus 6)
  • Attached the app login page snippet for reference.
  • Capability json:
    {
    “android”:
    {
    “platformName”: “android”,
    “automationName”: “uiautomator2”,
    “app”: “/Users/vishwajeetsingh/eclipse-workspace/src/test/resources/executableFile/V-Thru_com.vthru.apk”,
    “appPackage” : “com.vthru”,
    “appActivity”: “.MainActivity”,
    “adbExecTimeout” : 60000,
    “newCommandTimeout”: 60,
    “deviceName”: “android”,
    “autoGrantPermissions”: true,
    “noReset”: false
    }
    }

Code snippet:
public class LoginPage extends BasePage
{
public By txtBxContactNumber = By.xpath(“AbsoluteXpath1”);
public By txtBxEnterNumber = By.xpath(“AbsoluteXpath2”);
public By btnNext = By.xpath(“AbsoluteXpath3”);

public void login()
{
	elementAction.waitForVisible(txtBxContactNumber);
	elementAction.tap(txtBxContactNumber);
	elementAction.waitForPresent(txtBxEnterNumber, 10);
	elementAction.clear(txtBxEnterNumber);
	elementAction.type(txtBxEnterNumber, "1234567890");
	elementAction.tap(btnNext);
}

}

It is throwing error while finding first (txtBxContactNumber) element itself. Although, the same can be located using Appium Desktop.
Element action is a class in BaseClass having trusted piece of code
emphasized text

Tried workaround:
After spending close to 2 days on switching context, etc. i didn’t find the solution. Hence posting the query here for some help.

Kindly do let me know if in case you need any further details.

Many thanks in anticipation.!

From error we can say that element is not found with in the given 10 sec time.
Work Around: Increase wait time and give a try once.

After above work around still if you don’t find element, please check does your app set setWebContentsDebuggingEnabled to true or not? Try this and switch to web view hopefully you should find the elements in webview.

Try giving autoWebView:true in desired capabilities.

Hi @pothurajtharun,

Thanks for the response. Please do note below points:

  • I have increased the time to 120 sec.
  • Confirmed with Dev and there is no Web_View in application.
  • As a workaroud, i have tried updating autoWebView:true in capability.json but no luck.

Current scenario:

  • App is completely in Native view and has been built on React Native.
  • Able to locate element using Appium Desktop but getting Timeout exception (As the desired element is found) using script.

Thoughts please.!

Few workarounds…

  1. Try disabling the device animations, Animations might delay the execution.
  2. If the page source is huge, appium might take some time to parse the xml and search for the locators.so try increasing the wait time (max 4 to 5 mins).

I have done further debugging and found that i’m unable to interact with element even via Appium Desktop and getting InvalidElementState exception. Please do note, i can see the element is enabled and clickable too. Attached the snippet for reference.

Also as suggested, I have increased the time to 300 sec. but no luck.

@pothurajtharun @Ravi_Kishore @mykola-mokhnach @jonahss Tagging you guys for quick solution. :slight_smile:

@Vishwajeet_Singh with same screen share result of

System.out.println(driver.getPageSource());

at https://gist.github.com/ .

so we can see a bit more details.

@Aleksei Updated link with required details. Few points:

Current scenario:
Send keys is disabled by Dev intentionally as we need user to enter contact details at next page.

Issue:
Tapping is working fine with Appium Desktop but the same is failing using script and it throws timeout exception even after waiting for 5 mint.

@Vishwajeet_Singh I do not see link to page source.
the way you trying to find elements with huge xPath is totally wrong.

@Vishwajeet_Singh,

As per your screenshot invalidElementState exception is thrown when you try to perform some operation which is not applicable.

For example in ur case, if the textbox is disabled and if you try to perform type operation then it will throw an invalidElementState exception.

Can yo uplease provide the full screenshot of UIInspector with expansion of particular finding elements.

@Aleksei I understand using absolute xpath could lead to a very fragile tests - Hence, have already my dev to introduce unique locators for required elements. PFB the PageSource.

<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>

<android.widget.FrameLayout index=“0” package=“com.vthru” class=“android.widget.FrameLayout” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,0][1080,2201]" displayed=“true”>
<android.widget.LinearLayout index=“0” package=“com.vthru” class=“android.widget.LinearLayout” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,0][1080,2201]" displayed=“true”>
<android.widget.FrameLayout index=“0” package=“com.vthru” class=“android.widget.FrameLayout” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,80][1080,2201]" displayed=“true”>
<android.widget.LinearLayout index=“0” package=“com.vthru” class=“android.widget.LinearLayout” text="" resource-id=“com.vthru:id/action_bar_root” checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,80][1080,2201]" displayed=“true”>
<android.widget.FrameLayout index=“0” package=“com.vthru” class=“android.widget.FrameLayout” text="" resource-id=“android:id/content” checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,80][1080,2201]" displayed=“true”>
<android.widget.FrameLayout index=“0” package=“com.vthru” class=“android.widget.FrameLayout” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,80][1080,2201]" displayed=“true”>
<android.view.ViewGroup index=“0” package=“com.vthru” class=“android.view.ViewGroup” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,80][1080,2201]" displayed=“true”>
<android.view.ViewGroup index=“1” package=“com.vthru” class=“android.view.ViewGroup” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,80][1080,2201]" displayed=“true”>
<android.view.ViewGroup index=“0” package=“com.vthru” class=“android.view.ViewGroup” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,80][1080,2201]" displayed=“true”>
<android.view.ViewGroup index=“0” package=“com.vthru” class=“android.view.ViewGroup” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,80][1080,2201]" displayed=“true”>
<android.view.ViewGroup index=“0” package=“com.vthru” class=“android.view.ViewGroup” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,80][1080,2201]" displayed=“true”>
<android.view.ViewGroup index=“0” package=“com.vthru” class=“android.view.ViewGroup” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,80][1080,2201]" displayed=“true” />
<android.view.ViewGroup index=“1” package=“com.vthru” class=“android.view.ViewGroup” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,80][1080,2201]" displayed=“true”>
<android.view.ViewGroup index=“0” package=“com.vthru” class=“android.view.ViewGroup” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,80][1080,2201]" displayed=“true”>
<android.view.ViewGroup index=“0” package=“com.vthru” class=“android.view.ViewGroup” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,80][1080,2201]" displayed=“true”>
<android.view.ViewGroup index=“1” package=“com.vthru” class=“android.view.ViewGroup” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,80][1080,2201]" displayed=“true”>
<android.view.ViewGroup index=“0” package=“com.vthru” class=“android.view.ViewGroup” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,80][1080,2201]" displayed=“true”>
<android.view.ViewGroup index=“0” package=“com.vthru” class=“android.view.ViewGroup” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,80][1080,2201]" displayed=“true”>
<android.view.ViewGroup index=“0” package=“com.vthru” class=“android.view.ViewGroup” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,80][1080,2201]" displayed=“true” />
<android.view.ViewGroup index=“1” package=“com.vthru” class=“android.view.ViewGroup” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,80][1080,2201]" displayed=“true”>
<android.view.ViewGroup index=“0” package=“com.vthru” class=“android.view.ViewGroup” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,80][1080,2201]" displayed=“true”>
<android.view.ViewGroup index=“0” package=“com.vthru” class=“android.view.ViewGroup” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,80][1080,2201]" displayed=“true”>
<android.view.ViewGroup index=“1” package=“com.vthru” class=“android.view.ViewGroup” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,80][1080,2201]" displayed=“true”>
<android.view.ViewGroup index=“0” package=“com.vthru” class=“android.view.ViewGroup” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[131,776][949,907]" displayed=“true” />
<android.widget.TextView index=“1” package=“com.vthru” class=“android.widget.TextView” text=“V-THRU” checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[351,907][730,1075]" displayed=“true” />
<android.widget.TextView index=“2” package=“com.vthru” class=“android.widget.TextView” text=“The virtual drive-thru experience you´ve been waiting for.” checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[278,1115][803,1335]" displayed=“true” />
<android.view.ViewGroup index=“3” package=“com.vthru” class=“android.view.ViewGroup” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[0,2070][1080,2201]" displayed=“true”>
<android.view.ViewGroup index=“0” package=“com.vthru” class=“android.view.ViewGroup” text="" checkable=“false” checked=“false” clickable=“true” enabled=“true” focusable=“true” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[60,2109][1020,2201]" displayed=“true”>
<android.view.ViewGroup index=“0” package=“com.vthru” class=“android.view.ViewGroup” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[60,2109][1020,2201]" displayed=“true”>
<android.widget.ImageView index=“0” package=“com.vthru” class=“android.widget.ImageView” text="" checkable=“false” checked=“false” clickable=“false” enabled=“true” focusable=“false” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[102,2148][181,2200]" displayed=“true” />
<android.widget.EditText index=“1” package=“com.vthru” class=“android.widget.EditText” text="+965" checkable=“false” checked=“false” clickable=“true” enabled=“false” focusable=“true” focused=“false” long-clickable=“true” password=“false” scrollable=“false” selected=“false” bounds="[220,2148][1016,2200]" displayed=“true” />
</android.view.ViewGroup>
</android.view.ViewGroup>
</android.view.ViewGroup>
</android.view.ViewGroup>
</android.view.ViewGroup>
</android.view.ViewGroup>
</android.view.ViewGroup>
</android.view.ViewGroup>
</android.view.ViewGroup>
</android.view.ViewGroup>
</android.view.ViewGroup>
</android.view.ViewGroup>
</android.view.ViewGroup>
</android.view.ViewGroup>
</android.view.ViewGroup>
</android.view.ViewGroup>
</android.view.ViewGroup>
</android.view.ViewGroup>
</android.widget.FrameLayout>
</android.widget.FrameLayout>
</android.widget.LinearLayout>
</android.widget.FrameLayout>
</android.widget.LinearLayout>
</android.widget.FrameLayout>

@pothurajtharun @Aleksei fyi: This is the screenshot of respective screen. Please do note, I’m able to fetch text ‘The virtual drive-thru experience you´ve been waiting for.’ but getting Timeout exception when trying to click on text box (with +965).

try:

        MobileElement inputField = (MobileElement) driver.findElement(MobileBy.className("android.widget.EditText’"));
        WebDriverWait wait = new WebDriverWait(driver, 10); // 10 sec
        wait.until(ExpectedConditions.visibilityOf(inputField));
        // or
        // wait.until(ExpectedConditions.elementToBeClickable(inputField));
        inputField.clear();
        inputField.setValue("+965123456");
2 Likes

<android.widget.EditText index=“1” package=“com.vthru” class=“android.widget.EditText” text="+965" checkable=“false” checked=“false” clickable=“true” enabled=“false” focusable=“true” focused=“false” long-clickable=“true” password=“false” scrollable=“false” selected=“false” bounds="[220,2148][1016,2200]" displayed=“true” />

EditText enabled is set to false( which is nothing but disabled) so the reason you are getting invalidElementState exception when you are tryinng to perform some action on these disabled element via appium or scripts.

Ask your dev to enable the EditText & after that give a try with below scripts.

Try giving click event once instead of tap as below.

eleText=driver.findElement(By.xpath( "//android.widget.EditText[contains(@text,’ +965’)]));
driver.click(eleText);

or

Point p = driver .getElementLocation(eleText );
TouchAction t = new TouchAction( driver );
t.press( point (p.x, p.y)).release().perform();

Thanks for the quick response.

I have checked with my developer and he can’t change attribute value to enabled=true as we want user to enter text/contact number in upcoming/next page.

As suggested, I have done the changes and using below code in my script:
eleText=driver.findElement(By.xpath( "//android.widget.EditText[contains(@text,’ +965’)]));
driver.click(eleText);

So the question here is:
How to click on an element with clickable=“true” enabled=“false” in Android which has been developed in ReactNative.

*****It is possible manually but with script it’s throwing an error.

If developer won’t change attribute value to enabled=true. Then what you are trying to do with that disabled text field ?

If it is manually doable then exclude these test from your automation scripts or ask dev to provide different custom build for autoamtion execution with enabled=true , which you can work internally and it will be different to customer build.

You can’t perform any operation on disabled elements via scripts. For sure it throws exceptions.

@Vishwajeet_Singh You can get the coordinates of the element and use Tap by pixels. I’m not familiar with Java client code to provide the syntax, Hope you can figure it out.

Thanks everyone for the response. :slight_smile:

@Aleksei I have tried suggested approach and it’s working like charm. Thanks much again.! :star_struck: Any clue why it didn’t work when i have used hard sleep for close to 5 mint and then tried clicking an element.
Xpath i have used is same what i used this time: xpath ("//*[contains(@text, ‘+965’)]")

@pothurajtharun Text field is disabled for any text entry but it’s still clickable. Below is the page opens once you click the respective text box.

@Ravi_Kishore Sure, let me try this workaround too.

Hi, im new to appium.
Im unable to click on button created by “android.view.ViewGroup” although its clicking on button created by “android.widget.Button " on the same page.
here is the XML of android.view.ViewGroup (that i want to click on but .click() is not working on it
)
<android.view.ViewGroup index=“1” package=“com.pryze” class=“android.view.ViewGroup” text=”" resource-id=“com.pryze:id/language_card_english” checkable=“false” checked=“false” clickable=“true” enabled=“true” focusable=“true” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[18,193][702,333]" displayed=“true”>
<android.widget.TextView index=“0” package=“com.p” class=“android.widget.TextView” text=“English” resource-id=“com.pryze:id/txt_language_english” checkable=“false” checked=“false” clickable=“true” enabled=“true” focusable=“true” focused=“false” long-clickable=“false” password=“false” scrollable=“false” selected=“false” bounds="[299,231][421,296]" displayed=“true” />
</android.view.ViewGroup>

And here is the XML of android.widget.Button (that is clickable with same .click() method on the same page.

          <android.widget.Button index="4" package="com.p" class="android.widget.Button" text="CONTINUE WITH" resource-id="com.pryze:id/btn_continue_language" checkable="false" checked="false" clickable="true" enabled="true" focusable="true" focused="false" long-clickable="false" password="false" scrollable="false" selected="false" bounds="[18,1157][702,1245]" displayed="true" />

better use IDs:

  • btn_continue_language
  • language_card_english
  • txt_language_english

image

Yes, i have used IDs for both elements, also have checked for text “txt_language_english” but its not working.

Enable in developer menu show touches. Amd check where tap actually happen.