Android viewGroup问题-使用Appium测试

问题描述

是自动化测试的新手。
需要选择SWITCH选项。
努力为此编写代码(Android)。

enter image description here


由于此弹出窗口,测试失败。需要选择“切换”选项。 以下是我的测试步骤。测试在“登录后导航到通知中心时”失败

enter image description here

enter image description here

我的Java文件中该步骤的代码。
根据以下代码,如果元素notificationIconAfterLogin存在,则单击notificationHeader。

这里的notificationIconAfterLogin具有 xpath:(//android.widget.ImageView 13
notificationHeader具有 xpath:// * [@@ ==“ Notification Center”]

现在notificationIconAfterLoginAndroidOptional具有 xpath:(//android.view.ViewGroup 31
switchDeviceBtn具有 xpath:// * [@@ text ='SWITCH']

@Given("^I navigate to Notification Center after login$")
    public void iNavigateToNotificationCenterAfterLogin() throws Exception {
        if (elementExists(notificationIconAfterLogin)) {
            loopClickUntilFound(notificationIconAfterLogin,notificationHeader);
        } else {
            loopClickUntilFound(notificationIconAfterLoginAndroidOptional,switchDeviceBtn);
        }
        waitFor(3);
        screenshot(); // Cap screen in notification center
    }

enter image description here

未选择“我的开关”选项。 需要帮助来修复代码。
我在这里想念什么?还有其他办法吗?

解决方法

在 iNavigateToNotificationCenterAfterLogin() 方法中,首先检查是否显示了切换选项,然后点击切换按钮,然后执行您的常规操作

示例 Apium-Java 代码:

if(driver.findElements(By.xpath("//*[@text='SWITCH']")).size()==1)
{
    driver.findElement(By.xpath("//*[@text='SWITCH']")).click()
}

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...