AttributeError: 'NoneType' object has no attribute 'find_element'

51 Views Asked by At

I am facing some issue in my test script. What am I doing wrong here? Before that just an overview beforehand, its website testing in python and selenium using pytest. My selenium is v4.18.1 and Chrome v122.0.6261.112

conftest.py

enter image description here

Test_Regis.py:

enter image description here

I got this attribute error. But same I have written in very basic way. I have also written very basic of the same automation script. Below is same code as above.

enter image description here

This works fine. I do not understand what is wrong with the above code.

1

There are 1 best solutions below

0
Hai Vu On

You need to return the driver created in setup. I would also rename setup to driver:

# conftest.py
import pytest
from selenium import webdriver

@pytest.fixture
def driver():
    chrome_driver = webdriver.Chrome()
    chrome_driver.maximize_window()
    chrome_driver.get("...")
    return chrome_driver
# test_it.py
class TestRegistration:
    def test_reg001(self, driver):
        # Do something with driver
        pass

The key here is to return the driver you created.