我正在处理一个移动自动化项目,在获取属性值时遇到问题(例如,选中单选按钮或未选中复选框(。我正在使用Byorg.openqa.selenium.By
类,但我看到这个类与isEnabled()
、is Checked((、getText()
等方法不计数,就像Webdriver
一样,并且我在将其转换为SearchContext类以获得属性值时遇到了一个错误。
ExamplePage.locationSharingSwitch.findElement((SearchContext);
ExamplePage.locationSharingSwitch).isEnabled();
获取此错误
java.lang.ClassCastException:org.openqa.selene.By$ByXPath不能强制转换为org.openqa.selenium.SearchContext
有什么建议吗?
获取属性的正确方法是
MobileElement element = (MobileElement) driver.findElementByAccessibilityId("someId");
String isEnabled = element.getAttribute("enabled");
根据我的经验,元素可以被禁用并且仍然";启用";值为"0";真";。它实际上取决于组件实现,所以在100%的情况下我不会依赖它。