0

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

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.

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

4

1 回答 1

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)
于 2016-07-27T13:19:30.250 回答