2017-01-10 4 views
1

は私がlocators.pyTypeError例外:%のためのサポートされていないオペランドのタイプ(S): 'タプル' と 'str' は

class MainPageLocatars(object): 
    # Login function locators 
    TEST   = "//*[starts-with(@id,'table_')]/tbody/tr[%s]" 

を持って、私は以下のように、このロケータを呼び出しています:

INDEX_MAP = { 
    'First': '1', 
    'Last': 'last()' 
} 

# all locaters for this class are defined here only 
class ListView(Page): 

    def __init__(self, driver, index): 

     if index not in INDEX_MAP: 
      raise ValueError("Invalid index %s" % index) 

     self.driver = driver 
     self.row = self.driver.find_element_by_xpath(MainPageLocatars.FRAMEONE % (INDEX_MAP[index]) 

このそれを行う正しい方法ですか?

これは私が取得していますエラーです:

self.row = self.driver.find_element_by_xpath(MainPageLocatars.FRAMEONE % (INDEX_MAP[index])) 
    self.row = self.driver.find_element_by_xpath(MainPageLocatars.FRAMEONE % (INDEX_MAP[index])) 
TypeError: unsupported operand type(s) for %: 'tuple' and 'str' 
+3

明らかに、 'MainPageLocatars.FRAMEONE'はタプルです。 '%'はそれに何を期待していましたか? – jonrsharpe

+1

投稿されたコードによると、 'MainPageLocatars'は' FRAMEONE'属性を持っていません... –

+0

'MainPageLocatars.FRAMEONE%(INDEX_MAP [index]、))の最後に"カンマ " '。 –

答えて

1

は交換してください:

MainPageLocatars.FRAMEONE % (INDEX_MAP[index]) 

をすることにより:

MainPageLocatars.TEST % (INDEX_MAP[index]) 

文字列フォーマットを行うには。

+0

なぜフレームンを追加したのか分かりません。どうもありがとう。できます。 – user7242550

関連する問題