簡體   English   中英

用於Python中Selenium的Firefox Web驅動程序

[英]Firefox web driver for Selenium in Python

我在Python 3的OS X上將selenium 3.0.1與firefox 48一起使用。我無法使firefox用作webdriver。

from selenium import webdriver
driver = webdriver.Firefox()

給出以下錯誤:

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-21-fd567e24185f> in <module>()
----> 1 driver = webdriver.Firefox()

/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/selenium/webdriver/firefox/webdriver.py in __init__(self, firefox_profile, firefox_binary, timeout, capabilities, proxy, executable_path, firefox_options, log_path)
    133         if capabilities.get("marionette"):
    134             self.service = Service(executable_path, log_path=log_path)
--> 135             self.service.start()
    136
    137             capabilities.update(firefox_options.to_capabilities())

/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/selenium/webdriver/common/service.py in start(self)
     62             self.process = subprocess.Popen(cmd, env=self.env,
     63                                             close_fds=platform.system() != 'Windows',
---> 64                                             stdout=self.log_file, stderr=self.log_file)
     65         except TypeError:
     66             raise

/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/subprocess.py in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags, restore_signals, start_new_session, pass_fds)
    854                                 c2pread, c2pwrite,
    855                                 errread, errwrite,
--> 856                                 restore_signals, start_new_session)
    857         except:
    858             # Cleanup if the child failed starting.

/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/subprocess.py in _execute_child(self, args, executable, preexec_fn, close_fds, pass_fds, cwd, env, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite, restore_signals, start_new_session)
   1458                             else:
   1459                                 err_msg += ': ' + repr(orig_executable)
-> 1460                     raise child_exception_type(errno_num, err_msg)
   1461                 raise child_exception_type(err_msg)
   1462

OSError: [Errno 8] Exec format error

對於硒3或更高版本,您需要使用gecko驅動程序才能使Firefox運行:

Java的

System.setProperty("webdriver.gecko.driver","path of geckodriver.exe");
WebDriver driver = new FirefoxDriver();

蟒蛇

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
firefox_capabilities = DesiredCapabilities.FIREFOX
firefox_capabilities['marionette'] = True
firefox_capabilities['binary'] = 'C:\Users\test\tools\Firefox'
driver = webdriver.Firefox(capabilities=firefox_capabilities)
  1. 確保您下載了正確的tar.gz文件。
  2. 在轉到https://github.com/mozilla/geckodriver/releases之后 -查找macOS.tar.gz版本的geckodriver。
  3. 將其下載到桌面上並打開。
  4. 現在,在Finder中選擇“轉到”選項,然后選擇“轉到文件夾”。 輸入/ usr / local / bin,然后將geckodriver粘貼到垃圾箱中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM