selenium 状态码521,Selenium Firefox Webdriver导致错误:服务geckodriver意外退出。状态码为:2...

I'm writing a program that will search a website for specific entries inside of articles, I'm using selenium webdriver for Python.

While attempting to connect to the site I get this exception:

Traceback (most

recent call last):

File "search.py", line 26, in

test.search_for_keywords()

File "search.py", line 13, in search_for_keywords

browser = webdriver.Firefox()

File "C:\Python27\lib\site-packages\selenium-3.0.0b2-py2.7.egg\selenium\webdriver\firefox\webdriver.py", line 65, in __init__

self.service.start()

File "C:\Python27\lib\site-packages\selenium-3.0.0b2-py2.7.egg\selenium\webdriver\common\service.py", line 86, in start

self.assert_process_still_running()

File "C:\Python27\lib\site-packages\selenium-3.0.0b2-py2.7.egg\selenium\webdriver\common\service.py", line 99, in assert_process_still_running

% (self.path, return_code)

selenium.common.exceptions.WebDriverException: Message: Service geckodriver unexpectedly exited. Status code was: 2

It's saying that the webdriver unexpectedly exited. How can I fix this issue? I'm trying to connect with firefox version 48.0 with python version 2.7.12

解决方案

Running python selenium tests in latest Firefox browser (Version 47 above)

“Marionette" or "Gecko Driver” is the future version of firefox driver. Firefox 47+ is not compatible with the driver used in Selenium 2.53, and Selenium 3+ will be using a new driver called "Marionette" or "Gecko Driver" (which isn't officially released yet).

Prerequisites:

• Mozilla firefox : Version 50.0.2(Version 47 above)

• Selenium : Version 3.0.2

• Geckodriver : Version 0.11.1

• Python : Version 2.7.3

Setup:

• Selenium : pip install –U selenium

• Geckodriver : Download the geckodriver from https://github.com/mozilla/geckodriver/releases , unzip the file and place it in a folder

• Set the ‘Path’ environment variable with geckodriver path

Sample script:

from selenium import webdriver

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

#Provide the Firefox binary path

binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe’)

caps = DesiredCapabilities.FIREFOX.copy()

#Set ‘marionette’ browser to True

caps['marionette'] = True

#Launch the Firefox instance by specifying the geckodriver executable path

driver = webdriver.Firefox(firefox_binary=binary,capabilities=caps, executable_path`='D:/Installers/geckodriver-v0.11.1-win64/geckodriver')

You are done ...!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值