Reputation: 11
I am fairly new to Python and Selenium, and am trying to get some automated testing of our website off the ground. I am setting the tests up using the page object model so that changes to locators only need to be updated in one place. As part of this, I am setting up a function to wait for our subscribe button to be clickable. However, when I call this function I get the following error:
Traceback (most recent call last):
File "click_subscribe_button_test.py", line 51, in test_subscribe_click
main_page.wait_subscribe_button_clickable()
File "page.py", line 64, in wait_subscribe_button_clickable
wait.until(EC.element_to_be_clickable((*MainPageLocators.subscribe_button)))
TypeError: __init__() takes 2 positional arguments but 3 were given
I have read a number of related posts on here and other sites, and while they have helped me get closer to solving the issue, I am still encountering the above error. The relevant code is below, it is from two separate files as the locators are in a different file than the page objects.
page.py
def wait_subscribe_button_clickable(self):
subscribeElement = self.driver.find_element(*MainPageLocators.subscribe_button)
wait = WebDriverWait(self.driver,20)
wait.until(EC.element_to_be_clickable((*MainPageLocators.subscribe_button)))
locators.py
class MainPageLocators (object):
subscribe_button = (By.CSS_SELECTOR, 'li.last.leaf.subscribe')
The problem seems to be around the way I am pulling the locators from a separate file, since if I change
wait.until(EC.element_to_be_clickable((*MainPageLocators.subscribe_button)))
to
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'li.last.leaf.subscribe')))
The code works as intended.
There may be something I do not understand about how the *MainPageLocators.subscribe_button function is pulling the locators, but I have not been able to track down what is wrong.
Any help or guidance would be greatly appreciated.
Upvotes: 1
Views: 1302
Reputation: 474201
Just don't unpack the locator at all, pass it as is, as a tuple:
wait.until(EC.element_to_be_clickable(MainPageLocators.subscribe_button))
Upvotes: 2