user7242550
user7242550

Reputation: 261

Getting error unsupported operand type(s) for %: 'tuple' and 'str'

I have the locators.py

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

I am calling this locator as below:

from locators import *

def autoload(self, subFolder, fileName, logFile):
        # change made below
        beforeDate = self.find_element(MainPageLocatars.LOGFILELOCATOR % logFile).text

This is the right way to do it?

this is the error I am getting:

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

Upvotes: 0

Views: 3137

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 477607

MainPageLocatars.LOGFILELOCATOR is a tuple: indeed it contains two elements. There is no % operator defined on a tuple.

You should untuple and process the results:

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

Upvotes: 1

Related Questions