获取%的错误不支持的操作数类型:“tuple”和“str”

2024-09-21 11:07:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我有定位器.py在

class MainPageLocatars(object):
  # Login function locators
  LOGFILELOCATOR     = (By.XPATH, '//a[contains(@href, "%s")]/./../../td[7]')

我打电话给这个定位器如下:

^{pr2}$

这是正确的方法吗?在

这是我得到的错误:

   beforeDate = self.driver.find_element_by_xpath((AutoLoaderLocatars.LOGFILELOCATOR) % logFile).text
TypeError: unsupported operand type(s) for %: 'tuple' and 'str'

Tags: pybyobjectloginfunctionxpathclasstd
1条回答
网友
1楼 · 发布于 2024-09-21 11:07:27

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

相关问题 更多 >

    热门问题