Search code examples
javaappiumappium-android

Not able to click a button which is not enabled using Appium Java for Android app


I have to create a transfer. When I run the script the 'Transfer' button for which 'enabled' is false therefore script not able to tap 'Transfer' button & fails. I have attached a screen shot of uiautomator viewer dump.enter image description here

The workaround I found is to manually click on amount edit box and then this enables the on-screen android keyboard and by entering value manually for 'amount' field & then 'Transfer' button got enabled & can be clicked. But I am not sure how to enter value in edit box from on-screen android keyboard and then get rid of this keyboard to enter date & press 'Transfer' button. enter image description here

Your help is much appreciated. Thanks.


Solution

  • I am able to solve this problem. My approach is to first click on 'Amount' field and then do sendkeys the value of amount. For details see below code:-

        //locating the amount field using xpath
        MobileElement amount = driver.findElement(By.xpath("//android.widget.EditText[@resource-id='com.abc.rbanking:id/workflow_step_amount_value']"));
    
        amount.click();
    
        amount.sendKeys("1.25");
       //clicking and sendkeys would enable the disabled 'Transfer' button
    
       //locating the 'Date' field and click it. Clicking it would get rid of soft android keyboard
        driver.findElement(By.xpath("//*[@text = 'Date']")).click();
    
        Thread.sleep(3000);
    
        driver.findElement(By.id("com.abc.rbanking:id/back_button")).click();
    
        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    
        driver.findElement(By.xpath("//android.widget.Button[@resource-id='com.abc.rbanking:id/PrimaryButton' and @text='Transfer']")).click();