简体   繁体   中英

Opening firefox using selenium in python

I just installed selenium with pip like

pip install selenium

and installed

geckidriver.exe

and put it in

C:\\Program Files\\Mozilla Firefox

where my

firefox.exe

is in.

But when I run a code

from selenium import webdriver
browser = webdriver.Firefox()

it returns

C:\Users\asd\PycharmProjects\tomato\venv\Scripts\python.exe C:/Users/asd/Downloads/pycharmprojects/tomato/test.py
Traceback (most recent call last):
  File "C:/Users/asd/Downloads/pycharmprojects/tomato/test.py", line 2, in <module>
    browser = webdriver.Firefox()
AttributeError: module 'selenium.webdriver' has no attribute 'Firefox'

Process finished with exit code 1

I'm using python3 in anaconda3(32bit), on windows7(64bit).

What did I wrong?

Before start firefox, you need set the path where the binary is:

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary('C:\\Program Files\\Mozilla Firefox')
driver = webdriver.Firefox(firefox_binary=binary)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM