我正在为一个应用程序编写测试,我无法访问该应用程序的源代码,也没有任何与我关系密切的人。在某个时刻,我插入登录/密码信息,“登录”按钮变为绿色,我可以点击它。但是,我无法自动执行该操作,因为即使我可以点击屏幕上的按钮,其“可点击”属性仍然为 false,除了“已启用”之外的所有其他属性也是如此,“已启用”始终为 true ,即使按钮无法点击。 Screenshot of the node details on UIAutomatorViewer
我唯一能想到的就是当它变成绿色时点击它,但我不知道如何实现它,而且我不认为这是一个非常优雅的解决方案。 感谢任何帮助,在完成这部分之前我无法进行其他测试。
我正在使用 UI Automator Viewer 查看按钮的不同状态,并使用 WebDriverWait/ExpectedConditions 等待按钮可用。尽管它从未启用“可点击”属性,但我尝试使用 elementToBeClickable 和visibilityOfElementLocated,但没有成功。
这就是我现在所处的位置。
public void waitAndClick(String local) {
WebDriverWait wait = new WebDriverWait(getDriver(), 20);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath(local)));
getDriver().findElement(By.xpath(local)).click();
}
谢谢!
最佳答案
您可以获取元素位置,然后按坐标点击:
List<MobileElement> element = (MobileElement) getDriver().findElement(By.xpath(local));
Point location = element.getLocation();
ITouchAction action = new TouchAction(getDriver());
action.tap(location.x, location.y).perform();
关于java - 如何点击没有可点击的按钮:true state in Appium+Java?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57912297/