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()
}