I keep getting this error when try to run my code. I'm new to Python Selenium and I just can't get my head around this error:
TypeError: practicepagebutton() missing 1 required positional argument: 'self'
Test_e2e file:
from pageObjects.HomePage import HomePage
from pageObjects.LoginPage import LoginPage
from pageObjects.PracticePage import PracticePage
from utilities.BaseClass import BaseClass
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import pytest
import time
class TestAutomation(BaseClass):
def test_e2e(self):
homepage = HomePage(self.driver)
practicePage = HomePage.practicepagebutton()-------------> getting error on this line
practicePage.getPageTitle()
loginpage = PracticePage.testLoginPage()
loginpage.loginUsername().send_keys("student")
loginpage.loginPassword().send_keys("Password123")
loginpage.loginSubmit().click()
HomePage.py:
from selenium.webdriver.common.by import By
from pageObjects.PracticePage import PracticePage
class HomePage:
def __init__(self, driver):
self.driver = driver
practice = (By.XPATH, "//*[text()='Practice']")
def practicepagebutton(self):
self.driver.find_element(*HomePage.practice).click()
practicePage = PracticePage(self.driver)
return practicePage
PracticePage.py:
from selenium.webdriver.common.by import By
from pageObjects.LoginPage import LoginPage
class PracticePage:
def __init__(self, driver):
self.driver = driver
testLoginPageButton = (By.XPATH, "//*[text()='Test Login Page']")
def getPageTitle(self):
return self.driver.find_element(*PracticePage.testLoginPageButton).title()
def testLoginPage(self):
self.driver.find_element(*PracticePage.testLoginPageButton).click()
loginpage = LoginPage(self.driver)
return loginpage
LoginPage.py:
from selenium.webdriver.common.by import By
Error:
test_e2e.py::TestAutomation::test_e2e
============================== 1 failed in 4.03s ==============================
FAILED [100%]
test_e2e.py:15 (TestAutomation.test_e2e)
self = <test_e2e.TestAutomation object at 0x000002593CA5DE20>
def test_e2e(self):
homepage = HomePage(self.driver)
> practicePagee = HomePage.practicepagebutton()
E TypeError: practicepagebutton() missing 1 required positional argument: 'self'
test_e2e.py:18: TypeError
Process finished with exit code 1
Could someone please help me with this error?
The problem is that you're using the class directly, instead of creating an instance of the class.
Do this instead:
hp = HomePage(self.driver)
practicePagee = hp.practicepagebutton()