![](/img/trans.png)
[英]TypeError: unsupported operand type(s) for &: 'tuple' and 'tuple'
[英]TypeError: unsupported operand type(s) for %: 'tuple' and 'str'
我有 locators.py
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.TEST % (INDEX_MAP[index])
进行字符串格式化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.