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