Reputation: 783
I am writing my first Python Selenium page factory and am getting an error regarding my waits.
My code is as follows Basepage Class
class Basepage():
browser = None
def __init__(self, browser):
self.browser = browser
self.base_url = config.url
def wait_for_element(self, *element):
WebDriverWait(self.browser, 10).until(
EC.presence_of_element_located(*element)
)
def click_element(self, *element):
self.browser.find_element(*element).click()
def find_element(self, *element):
self.browser.find_element(*element)
CreatePage Class
class CreatePage(Basepage):
def isat_createpage(self):
self.wait_for_element(*CreatePageLocators.add_computer_title)
text = self.find_element(*CreatePageLocators.add_computer_title).text
if text == "Add a computer":
return True
else:
return False
Behave Step @then('the user will be navigated to "Create_Computer" page') def step_impl(context): page = CreatePage(context.browser) assert page.isat_createpage(), "not at ADD Computer page"
Locator I am using for the item
class CreatePageLocators:
add_computer_title = (By.XPATH, "//*[@id=\"main\"]/h1")
I am getting the error
Scenario: User can open Create Computer screen # features/UI_Tests/Create.feature:8
Given A user has navigated to the BB_Test_Webpage # steps/Backbase_common_steps.py:6
And add a new computer is clicked # steps/Backbase_common_steps.py:11
Then the user will be navigated to "Create_Computer" page # steps/web_create_steps.py:5
Traceback (most recent call last):
File "c:\users\richard.cariven\python\lib\site-packages\behave\model.py", line 1329, in run
match.run(runner.context)
File "c:\users\richard.cariven\python\lib\site-packages\behave\matchers.py", line 98, in run
self.func(context, *args, **kwargs)
File "steps\web_create_steps.py", line 8, in step_impl
assert page.isat_createpage(), "not at ADD Computer page"
File "C:\Users\richard.cariven\Documents\Backbase_Test_RC\modules\pages\createpage.py", line 15, in isat_createpage
self.wait_for_element(*CreatePageLocators.add_computer_title)
File "C:\Users\richard.cariven\Documents\Backbase_Test_RC\modules\pages\basepage.py", line 23, in wait_for_element
EC.presence_of_element_located(*element)
TypeError: __init__() takes 2 positional arguments but 3 were given
I imagine I am doing something very simple wrong. But help greatly appreciated
Upvotes: 2
Views: 856
Reputation: 33384
If you check the error it is mentioned about positional arguments.
EC.presence_of_element_located(*element) TypeError: init() takes 2 positional arguments but 3 were given
Change the following inside function like that add one more parenthesis.
def wait_for_element(self, *element):
WebDriverWait(self.browser, 10).until(
EC.presence_of_element_located((By.XPATH, "//*[@id='main']/h1")))
Upvotes: 1