我有locators.py
class MainPageLocatars(object):
# Login function locators
LOGFILELOCATOR = (By.XPATH, '//a[contains(@href, "%s")]/./../../td[7]')
我正在调用此定位器,如下所示:
from locators import *
def autoload(self, subFolder, fileName, logFile):
# change made below
beforeDate = self.find_element(MainPageLocatars.LOGFILELOCATOR % logFile).text
这是正确的方法吗?
这是我得到的错误:
beforeDate = self.driver.find_element_by_xpath((AutoLoaderLocatars.LOGFILELOCATOR) % logFile).text
TypeError: unsupported operand type(s) for %: 'tuple' and 'str'
答案 0 :(得分:1)
MainPageLocatars.LOGFILELOCATOR
是一个元组:实际上它包含两个元素。元组上没有定义%
运算符。
你应该解决并处理结果:
def autoload(self, subFolder, fileName, logFile):
#first obtain the two elements in the tuple
(a,b) = MainPageLocatars.LOGFILELOCATOR
#next find the element and use the % operator in the string
beforeDate = self.find_element((a,b%logFile)).text