NiPa
NiPa

Reputation: 93

EC don`t work with locators from another file

I am trying to seporate my locators from page object classes. And it works perfectry with driver.find_element. But if i an trying to use it with EC, like self.wait.until(EC.visibility_of_element_located(*OrderLocators.file_upload_in_process))

I get this error

File "C:\FilePath\ClabtFirstForm.py", line 95, in wait_for_file_upload
    wait.until(EC.visibility_of_element_located(*OrderLocators.file_upload_in_process))
TypeError: __init__() takes 2 positional arguments but 3 were given

My test method

def test_files_regular(self):
    project_path = get_project_path()
    file = project_path + "\Data\Media\doc_15mb.doc"
    self.order.button_upload_files()
    self.order.button_select_files(file)
    self.order.wait_for_file_upload()

Page object class

class CreateOrder(object):

def __init__(self, driver):
    self.driver = driver
    self.wait = WebDriverWait(driver, 25)

def button_upload_files(self):
    self.driver.find_element(*OrderLocators.button_upload_files).click()

def button_select_files(self, file):
    self.driver.find_element(*OrderLocators.button_select_files).send_keys(file)

def wait_for_file_upload(self):
    self.wait.until(EC.visibility_of_element_located(*OrderLocators.file_upload_in_process))
    self.wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "[ng-show='item.isSuccess']")))

Locators

class OrderLocators(object):

    button_upload_files = (By.CLASS_NAME, 'file-upload-label')
    button_select_files = (By.CLASS_NAME, 'input-file')
    file_upload_in_process = (By.CSS_SELECTOR, "[ng-show='item.isUploading']")

Upvotes: 1

Views: 62

Answers (1)

Todor Minakov
Todor Minakov

Reputation: 20067

When you are passing the arguments to visibility_of_element_located()with *, you're in fact passing the expanded iterable OrderLocators.file_upload_in_process. That is, this call:

visibility_of_element_located(*OrderLocators.file_upload_in_process)

, is the same as:

visibility_of_element_located(By.CLASS_NAME, 'input-file')

Note how in the second line the method is actually called with two arguments.

In the same time, this condition's constructor expects only a single argument - a tuple/list of two elements; thus the exception.

The fix - pass to it what it expects, the tuple itself, without expending it:

visibility_of_element_located(OrderLocators.file_upload_in_process)

Upvotes: 3

Related Questions