Unable to perform click or sendkeys in Appium

192
January 25, 2018, at 00:09 AM

I'm trying to click on a button in Android app using Appium but no luck.

Element in UIAutomatorViewer

Using below code for the same :

PageClass

public class MyProfilePage 
{
    AndroidDriver<MobileElement> driver;
    @FindBy(id="com.rawalinfocom.rcontact:id/image_right_left") 
    public WebElement profileEditIcon;
    @FindBy(id="com.rawalinfocom.rcontact:id/input_first_name") 
    public WebElement firstName;
    @FindBy(id="com.rawalinfocom.rcontact:id/input_last_name")  
    public WebElement lastName;
    @FindBy(id="com.rawalinfocom.rcontact:id/button_name_update")   
    public WebElement updateButton;
    @FindBy(id="com.rawalinfocom.rcontact:id/snackbar_text")    
    public WebElement notificationMessage;
    public MyProfilePage(AndroidDriver<MobileElement> driver)
    {
        PageFactory.initElements(driver, this);
        this.driver=driver;
    }
    public void clickProfileEditIcon()
    {
        profileEditIcon.click();
    }
    public String getFirstName()
    {
        return firstName.getText();
    }
    public void enterFirstName(String name)
    {
        firstName.clear();
        firstName.sendKeys(name);
    }
    public void enterLastName(String name)
    {
        lastName.clear();
        lastName.sendKeys(name);
    }
    public void clickUpdateButton()
    {
        updateButton.click();
    }
    public String getNotificationMessage()
    {
        return notificationMessage.getText();
    }
}

And Here testcase class

@Test
public void updateFirstNameAndVerifyChanges()
{
    homepage.clickBreadCrumbIcon();
    drawer.clickUsername();
    myprofilepage.clickProfileEditIcon();
    WaitHelper.waitUntilElementGetClickable(driver, myprofilepage.firstName);
    myprofilepage.enterFirstName(reader.getCellData(0, 4, 1));
    myprofilepage.clickUpdateButton();
    WaitHelper.waitUntilElementHasText(driver, myprofilepage.notificationMessage);
    System.out.println(myprofilepage.getNotificationMessage());
}

But not able to do even single action (click or send keys) on this activity. Always getting NoSuchElementException

Answer 1

Try code below:

public class MyProfilePage 
{
    AndroidDriver<MobileElement> driver;
    @FindBy(id="image_right_left") 
    public WebElement profileEditIcon;
    @FindBy(id="input_first_name") 
    public WebElement firstName;
    @FindBy(id="input_last_name")  
    public WebElement lastName;
    @FindBy(id="button_name_update")   
    public WebElement updateButton;
    @FindBy(id="snackbar_text")    
    public WebElement notificationMessage;
    public MyProfilePage(AndroidDriver<MobileElement> driver)
    {
        PageFactory.initElements(driver, this);
        this.driver=driver;
    }
    public void clickProfileEditIcon()
    {
        profileEditIcon.click();
    }
    public String getFirstName()
    {
        return firstName.getText();
    }
    public void enterFirstName(String name)
    {
        firstName.clear();
        firstName.sendKeys(name);
    }
    public void enterLastName(String name)
    {
        lastName.clear();
        lastName.sendKeys(name);
    }
    public void clickUpdateButton()
    {
        updateButton.click();
    }
    public String getNotificationMessage()
    {
        return notificationMessage.getText();
    }
}

If still not work use Xpath in place of id in your code.

READ ALSO
How to compare two unreadable file and get difference in java?

How to compare two unreadable file and get difference in java?

I have two files exported from one software which have same content while exporting but once it is exported and when i compare two files , it shows differenceIn fact, size of both files are same

188
How to remove the null before resultant string after concatenation..?

How to remove the null before resultant string after concatenation..?

How to remove the null after concatenation of two strings

150
Signing iOS .mobileconfig with Bouncy Castle

Signing iOS .mobileconfig with Bouncy Castle

Based on Replicating 'openssl smime' in Java with Bouncy Castle? I try to replicating programmatically this command:

207
Difference between the sqlContext and by loading the driver of the dataBase

Difference between the sqlContext and by loading the driver of the dataBase

What is the difference if i use the sqlContext to get the information from the database

155