2017-01-10 30 views
1

我有locators.py类型错误:对于不支持的%操作数类型(S): '元组' 和 '海峡'

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

哦,我不知道为什么我添加了frameone。非常感谢。有用。 – user7242550

相关问题