从emulator appium获取属性值

ie3xauqp  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(386)

我在一个移动自动化项目中工作,并且在获取属性值时遇到了问题(例如,如果选中了单选按钮或未选中的复选框)。我正在使用 org.openqa.selenium.By 但我发现这个类不适用于 isEnabled() ,已选中(), getText() 就像 Webdriver 是的,我得到一个错误,将其转换为searchcontext类以获得属性值。

ExamplePage.locationSharingSwitch.findElement((SearchContext);
ExamplePage.locationSharingSwitch).isEnabled();

获取此错误
java.lang.classcastexception:org.openqa.selenium.by$byxpath不能转换为org.openqa.selenium.searchcontext
有什么建议吗?

xqk2d5yq

xqk2d5yq1#

获取属性的正确方法是

MobileElement element = (MobileElement) driver.findElementByAccessibilityId("someId");
String isEnabled = element.getAttribute("enabled");

根据我的经验,元素可以被禁用,而“enabled”值仍然是“true”。它实际上取决于组件实现,所以我不会在100%的情况下依赖它。

相关问题