Reputation: 7708
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
Upvotes: 1
Views: 1197
Reputation: 7708
I got the solution :
Actually the issue was related to the Virtual Device. I was using NEXUS 5 API 24 Android version 7 virtual device
I've changes to Google Nexus 6 API 23 Android version 6.0 virtual device and It working fine
Might be device dependent issue
Upvotes: 0
Reputation: 364
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.
Upvotes: 1