首页 > 解决方案 > 如何在Python中找到具有相同ID的appium中的多个元素?

问题描述

我正在 python 的 Andriod 项目的 Appium 中编写测试代码。问题是我无法访问具有相同 Id 的两个不同 Activity 中的两个按钮。我试图以这种方式访问​​第二个按钮。但它们都不起作用。如何解决问题? driver.find_element_by_id("com.myapp.testApp:id/login[1]").click(), driver.find_element_by_class_name("android.widget.Button").click() driver.find_element_by_xpath("(//button[@id='login'])[1]").click() driver.find_element_by_xpath("//android.widget.Button[@text='Change Password']").click()

标签: appiumappium-androidappium-iospython-appiumappium-desktop

解决方案


使用.find_elements*

elements = driver.find_elements_by_xpath("xpath")
#check elements number
print(len(elements))
#click second element
elements[1].click()

推荐阅读