gpt4 book ai didi

java - 无法在 Appium 中执行点击或发送键

转载 作者:行者123 更新时间:2023-11-30 00:09:17 25 4
gpt4 key购买 nike

我正在尝试使用 Appium 单击 Android 应用程序中的按钮,但没有成功。

UIAutomatorViewer 中的元素

enter image description here

同样使用下面的代码:

页面类

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();
}
}

这里是测试用例类

@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());
}

但无法对此 Activity 执行单一操作(单击或发送键)。总是得到 NoSuchElementException

最佳答案

尝试下面的代码:

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();
}
}

如果仍然不能工作,请使用 Xpath 代替代码中的 id。

关于java - 无法在 Appium 中执行点击或发送键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48422759/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com