Home > database >  Selenium webdriver not recognized as webdriver
Selenium webdriver not recognized as webdriver

Time:09-22

So I have this test and fixture:

@pytest.fixture()
def init_driver():
    return webdriver.Chrome(executable_path=TestParams.CHROME_EXECUTABLE_PATH)


@pytest.mark.usefixtures('init_driver')
def test_1():
    driver = init_driver
    login(driver)

In this case my driver type is <class 'function'> so I cannot use its function for example get and got this error:

AttributeError: 'function' object has no attribute 'get'

When I change it to this:

@pytest.mark.usefixtures('init_driver')
def test_1():
    login(webdriver.Chrome(executable_path=TestParams.CHROME_EXECUTABLE_PATH))

My driver type is <selenium.webdriver.chrome.webdriver.WebDriver (session="4ca3cb8f5bcec7a7498a65bfe5a2ea81")>

And all works fine.

What I am doing wrong ?

CodePudding user response:

I fixed the syntax and changed it so that it runs without your hidden methods and variables such as login() and TestParams:

import pytest
from selenium import webdriver

@pytest.fixture()
def init_driver():
    driver = webdriver.Chrome()
    yield driver
    driver.quit()

def test_1(init_driver):
    driver = init_driver
    print(type(driver))

Running that prints:

<class 'selenium.webdriver.chrome.webdriver.WebDriver'>
  • Related