Appium Android 自动化用 pagefactory 的模式去实现,初始化的 WebElement 类型元素无法转成 RemoteWebElement 或 AndroidElement 类型

黄俊 · 2017年12月22日 · 960 次阅读

public class PGmasterHomePage extends PreservationMaster {

AndroidDriver driver;
public PGmasterHomePage(AndroidDriver driver){
PageFactory.initElements(driver, this);
this.driver=driver;
}

@FindBy(id="com.xx.security:id/xxxx")
public WebElement MasterListTitle;

@FindBy(id="com.xx.security:id/xxxx")
public WebElement MasterListTab;

使用了 PageFactory 的模式去搞 一下 Android 自动化,在初始化 page object 后。控件元素去进行 press() 操作时,会报出如下错误
com.sun.proxy.$Proxy7 cannot be cast to org.openqa.selenium.remote.RemoteWebElement

press 函数的源码如下:
public TouchAction press(WebElement el) {
ActionParameter action = new ActionParameter("press", (RemoteWebElement) el);
parameterBuilder.add(action);
return this;
}
猜想错误的原因是通过 PageFactory.initElements(driver, this);初始化的 WebElement 控件元素无法进行类型转换,因为尝试把 WebElement 的控件元素转成 AndroidElement 类型,
同样会报出 cannot be cast to 的错误。

请各方大神赐教,如何解决用这样的问题,谢谢!

共收到 0 条回复 时间 点赞
1楼 已删除
需要 登录 後方可回應,如果你還沒有帳號按這裡 注册