Having difficulties using selenium module

Question:

I’m still new to python and I was experimenting with selenium. It opens a Firefox browser when I use it directly from the Windows terminal. But when I change the directory to desktop and try to open the browser from there, it say the ‘geckodriver’ isn’t in Path. I have the driver in path

This is my code:

from selenium import webdriver

browser = webdriver.Firefox()

And sometimes the browser opens but it closes immediately

Asked By: Kai

||

Answers:

According to docs: Selenium Documentation, you have to initiate driver, you can do this with hard coded location, example:

from selenium.webdriver.firefox.service import Service
from selenium import webdriver

service = Service(executable_path="/path/to/geckodriver")
driver = webdriver.Firefox(service=service)

then, to take an action on browser, you need to get a page, example:

driver.get("https://www.selenium.dev/selenium/web/web-form.html")
Answered By: Bartosz