Reputation: 93
I am trying to implement POM model in my autotests and I have a problem with separating locators to another file. I am using this as guide https://selenium-python.readthedocs.io/page-objects.html
My page object
from Locators.Sites.SitesLocators import SitesLocators
class ResetPasswordFirstForm(object):
def __init__(self, driver):
self.driver = driver
self.wait = WebDriverWait(self.driver, 20)
def button_go_to_reset_passwrod(self):
self.driver.find_element(*SitesLocators.button_go_to_reset_password).click()
def button_submit_form(self):
self.driver.find_element(*SitesLocators.button_submit_reset_password).click()
My locators
class SitesLocators(object):
button_go_to_reset_password = (By.CSS_SELECTOR, "a[href='#/reset-password']")
button_submit_reset_password = (By.CSS_SELECTOR, "[ng-click='send()']")
But i get this error
TypeError: __init__() takes 2 positional arguments but 3 were given
What is the best way to separate my locators and use them correct?
Upvotes: 1
Views: 1187
Reputation: 5204
As I see it the Error:
TypeError: init() takes 2 positional arguments but 3 were given
Means you need to add a third argument to the __init()__
:
This is your current __init()__
:
def __init__(self, driver):
self.driver = driver
self.wait = WebDriverWait(self.driver, 20)
As you quoted in your question the selenium page-objects you can see here that they have a third argument (although not always used see owner
).
So just add a third one it should do the trick!
As you can see here:
def __get__(self, obj, owner):
"""Gets the text of the specified object"""
driver = obj.driver
WebDriverWait(driver, 100).until(
lambda driver: driver.find_element_by_name(self.locator))
element = driver.find_element_by_name(self.locator)
return element.get_attribute("value")
Hope this helps you!
Upvotes: 2