使用appium查找元素

时间:2016-07-26 08:08:58

标签: android appium python-appium

变量扩展不会在多个引号内发生。这是代码

products = ['One','Two','Three'] 
for i in range(0,len(products)):
     el = self.driver.find_element_by_android_uiautomator('new UiSelector().text("{}")').format(products[i])
                print (el)

预期结果应为:

el = self.driver.find_element_by_android_uiautomator('new UiSelector().text("One")')

错误讯息:

File "temp_test.py", line 84, in test_product
    el = self.driver.find_element_by_android_uiautomator('new UiSelector().text("{}")').format(products[i])
NoSuchElementException: Message: An element could not be located on the page using the given search parameters.

请帮我解决这个问题!!!

1 个答案:

答案 0 :(得分:0)

最后,通过多次尝试(差不多半天)得到了答案。它很简单,.format(products[i])应在括号()和引号末尾指定。

products = ['One','Two','Three'] 
for i in range(0,len(products)):
     el = self.driver.find_element_by_android_uiautomator('new UiSelector().text("{}")'.format(products[i]))
                print (el)