0
我想使用Appium和python自动化一个Android应用程序。我有一个列表视图的屏幕,我想创建一个遍历列表的函数,并返回列表中的名称,然后将其与预期列表进行比较(字母顺序很重要)。我想将这个函数用于可能具有不同长度列表的屏幕,我是否需要能够首先确定列表的长度。如何使用python获取ExpandableListView for Appium中的项目数量?
actual_names = []
expected_names = ["Abe", "Bob", "Carl"]
for num in range(1, 4):
xpat = "//android.widget.ExpandableListView[1]/android.widget.FrameLayout[" + str(num) + "]/android.widget.RelativeLayout[1]/android.widget.TextView[1]"
text = appium_driver.find_element_by_xpath(xpat).text
actual_names.append(text)
assert expected_names == actual_names
此代码的工作原理,但只适用于一个屏幕,只有列表中的项目的确切数量。如果列表中的项目数量发生更改,则失败。这非常脆弱。我怎样才能改善这一点并使其更具活力?我使用Python 3和Appium 1.5.3
这工作!非常感谢。我不知道你可以使用没有索引号的xpaths。 – Cody