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'
很明顯'MainPageLocatars.FRAMEONE'是一個元組。你期待'%'做什麼? – jonrsharpe
根據發佈的代碼,'MainPageLocatars'甚至沒有'FRAMEONE'屬性... –
嘗試在'... MainPageLocatars.FRAMEONE%(INDEX_MAP [index],))末尾添加「逗號」 '。 –