Python TypeError:不支持%的操作数类型:';元组';和';str';

Python TypeError:不支持%的操作数类型:';元组';和';str';,python,selenium,Python,Selenium,我有定位器 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 o

我有定位器

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'
替换:

MainPageLocatars.FRAMEONE % (INDEX_MAP[index])
作者:


执行字符串格式化。

显然
MainPageLocatars.FRAMEONE
是一个元组。您希望
%
对它做什么?根据发布的代码,
MainPageLocatars
甚至没有
FRAMEONE
属性…尝试在
…MainPageLocatars.FRAMEONE%的末尾添加一个“逗号”(INDEX\u MAP[INDEX],))
@RafaelAguilar然后他可能只会得到
TypeError:不支持%的操作数类型:'tuple'和'tuple'
哦,我不确定为什么要添加frameone。谢谢。它起作用了。
MainPageLocatars.TEST % (INDEX_MAP[index])