Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 获取%不支持的操作数类型时出错:';元组';和';str';_Python_Selenium - Fatal编程技术网

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