Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium not working in Python

I have problem with Selenium! I tried both 3.6 and 2.7 but no difference! I'm using win7 (64bit)

let's start with a simple code:

binary = FirefoxBinary(r"C:\Program Files\Mozilla Firefox\firefox.exe")
fp = webdriver.FirefoxProfile()
driver = webdriver.Firefox(firefox_binary=binary, firefox_profile=fp)

And so, i get these errors:

C:\Python27\python.exe E:/Python/MathBattle_Solver/test.py

Traceback (most recent call last): File "E:/Python/MathBattle_Solver/test.py", line 13, in download("https://www.google.com")

File "E:/Python/MathBattle_Solver/test.py", line 9, in download browser = webdriver.Firefox(capabilities=firefox_capabilities, executable_path=r'C:\Windows\System32\geckodriver.exe')

File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 144, in init self.service.start()

File "C:\Python27\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start os.path.basename(self.path), self.start_error_message)

selenium.common.exceptions.WebDriverException: Message: 'geckodriver.exe' executable needs to be in PATH.

I downloaded the "geckodriver.exe", put it into the system32 folder and added into PATH system variable from the environment variables but nothing happened! still the same error!

Any idea?

like image 244
MohamadKh75 Avatar asked Dec 06 '25 08:12

MohamadKh75


2 Answers

It works for me on 52.0.2 (64bit) and Geckodriver 0.15.0-win64 (from https://github.com/mozilla/geckodriver/releases).

Put geckodriver.exe in the script folder and then call webdriver.Firefox with

driver = webdriver.Firefox(firefox_binary=binary, firefox_profile=fp, executable_path='geckodriver.exe')
like image 160
fedterzi Avatar answered Dec 08 '25 21:12

fedterzi


Selenium requires a driver to interface with the chosen browser. Firefox, for example, requires geckodriver, which needs to be installed before the below examples can be run. Make sure it’s in your PATH, e. g., place it in /usr/bin or /usr/local/bin.

Failure to observe this step will give you an error selenium.common.exceptions.WebDriverException: Message: ‘geckodriver’ executable needs to be in PATH

Put geckodriver.exe in the script folder and then call webdriver.Firefox with

like image 32
GHULAM NABI Avatar answered Dec 08 '25 22:12

GHULAM NABI



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!