2016-07-26 13 views
0

複数の引用符では変数の展開が行われません。appium find要素を使用した複数引用符でのPython変数の展開

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

エラーメッセージ:ここにコード

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) 

期待される結果があるべきである

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. 

私はこの問題を解決するために助けてください!

答えて

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) 
関連する問題