appium - 如何在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()
解决方案
使用.find_elements*
:
elements = driver.find_elements_by_xpath("xpath")
#check elements number
print(len(elements))
#click second element
elements[1].click()
推荐阅读
- tensorflow - Tensorflow Hub + Estimator 潜在错误:训练后的权重未重用于评估/预测
- rest - SAP PI RFC 到 REST 通信,无需映射。可能的?
- oracle - 从数据库查询中发送带有新记录的电子邮件
- github - 通过 GitHub API 访问链接的 SAML 身份
- java - 将文本输入编辑到数组中
- java - 下一个活动android中仍然存在启动画面
- c++ - 具有 std::map 和 std::variant 的不完整类型
- bar-chart - 如何在 Tableau 中显示最近几天的数据但从一开始就累积记录
- xslt - XSLT:从 for-each/select 中删除“”标签
- java - 方法效率低下