首页 > 解决方案 > 在@android 中为appium 编写Sendkeys commnad

问题描述

我们如何通过说在 Android 中编写 SendKeys 命令@android

MobileElement username  = (MobileElement) driver.findElementById("com.devere.dcx:id/editTextemail");
username.sendKeys("shr@yopmail.com");

我想把它写成这样的android命令:

@ android findElementById("com.devere.dcx:id/editTextemail");
username.sendKeys("shr@yopmail.com");

标签: appiumsendkeys

解决方案


如果要使用注释访问元素,可以使用页面对象模型。以下是页面对象模型的示例。

public class Abcd {
    //you can access element using accessibility, id and xpath

    @AndroidFindBy(accessibility = "your cont-desc")
    private MobileElement textInput;

    @AndroidFindBy(id = "your element's id")
    private MobileElement btn;

    public Abcd(AppiumDriver<MobileElement> driver) {
        PageFactory.initElements(new AppiumFieldDecorator(driver), this);
    }

    public boolean inputEmail(String email) {
        textInput.sendkey(email)
    }
}

现在在你的测试课上你可以做

Abcd abcd=new Abcd(driver);
abcd.inputEmail("shr@yopmail.com");

您必须将 AppiumDriver 定义为静态


推荐阅读