selenium
selenium copied to clipboard
[🐛 Bug]: Unable to access methods of WebDriver class when the WebDriver instance is passed to test class from conftest.py
What happened?
Not getting any suggestion regarding the webdriver in test class. ( Both in pycharm and vscode ) The code is working fine but its very difficult to type all the code manually without giving the suggestions.
How can we reproduce the issue?
Created conftest.py
code :
import pytest
from selenium import webdriver
@pytest.fixture(scope="class", autouse=True)
def driverInit(request):
driver = webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(10)
driver.get("https://opensource-demo.orangehrmlive.com/web/index.php/auth/login")
request.cls.driver = driver
yield
driver.close
Test class file
Code :
import pytest
from selenium.webdriver.common.by import By
@pytest.mark.usefixtures("driverInit")
class TestOne:
def test_loginScenario(self):
self.driver.find_element(By.XPATH, "//input[@name='username']").send_keys("Admin")
self.driver.find_element(By.XPATH, "//input[@name='password']").send_keys("admin")
self.driver.
here after the self.driver. no suggestion?
Details :
pycharm community edition Version: 2024.1.4
python version : Python 3.12.4
pytest version : pytest 8.3.2
Relevant log output
No suggestions for webdriver is showing in test class level
Operating System
windows
Selenium version
4.23.0
What are the browser(s) and version(s) where you see this issue?
Chrome and firefox
What are the browser driver(s) and version(s) where you see this issue?
Chrome Version 127.0.6533.89 (Official Build) (64-bit)
Are you using Selenium Grid?
No response
@Shipinpk, thank you for creating this issue. We will troubleshoot it as soon as we can.
Info for maintainers
Triage this issue by using labels.
If information is missing, add a helpful comment and then I-issue-template label.
If the issue is a question, add the I-question label.
If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.
If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C),
add the applicable G-* label, and it will provide the correct link and auto-close the
issue.
After troubleshooting the issue, please add the R-awaiting answer label.
Thank you!
I am not able to reproduce. Can you share a complete project so we can check it?
Also, how come it works for the first two find_element and not anymore?
PythonVsCode.zip Hi @diemol The issue is am not getting any suggestions after self.driver. ? The above 2 lines of code were written manually without any suggestions. Note : The execution is working fine no issue for that
But according to the suggestion of self.driver. is the probelm. In future we have to write a lots of code, so without suggestion or auto completion manually writing all the codes like find_element is very difficult and it will leads to make confusion.
Here I attached a sample code for this. Please let me know if you need more details.
Would this not be an IDE issue? I'm not 100% sure what can even be done from this end.
Tried with VScode and pycharm edition, the same issue is still there irrespective of IDE. So its not an IDE issue
I am also facing the same issue in the below code
In conftest.py -
import pytest from selenium import webdriver
@pytest.fixture(scope="class") def driver(request): driver = webdriver.Chrome() driver.get("https://google.com")
request.cls.driver = driver
yield
driver.quit()
In another file test_login.py
import pytest from testcases.conftest import driver
@pytest.mark.usefixtures("driver") class VerifyLoginTest:
def test_login(self):
self.driver.
Details : pycharm community edition Version: 2024.3.2 python version : Python 3.13.1 pytest version : pytest 8.3.4
can anyone help with this issue i am stuck with this from last 2 days and not able to find any solution
If this were a general issue, I would expect more people to be chiming in.
We are adding typing to Python but it takes time. In addition, I read that you can add type hinting to help this case, like:
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
@pytest.mark.usefixtures("driverInit")
class TestOne:
driver: webdriver.Chrome # Add this line for type hinting.
def test_loginScenario(self):
self.driver.find_element(By.XPATH, "//input[@name='username']").send_keys("Admin")
self.driver.find_element(By.XPATH, "//input[@name='password']").send_keys("admin")
For now, there is nothing we can do on our side. If you have any ideas, please let us know.
This issue has been automatically locked since there has not been any recent activity since it was closed. Please open a new issue for related bugs.