2017-01-22 9 views
0

私は初めてSelenium Webdriverを試しています。私はPython 3.6にアップデートして、セレンも再インストールしました。基本的なウェブページを開こうとしているのは間違っています。コードは次のとおりです。PythonトレースバックエラーのためのSelenium Webdriver

from selenium import webdriver 
driver = webdriver.Firefox() 
driver.get("http://www.python.org") 

これは基本的ですが、まだ機能していません。それは私の解釈能力を超えたいくつかのエラーを投げている。もちろん、私は問題を見つけようとしましたが、何も助けに見えませんでした。私はどんな入力にも感謝します。これらはエラーです:

Traceback (most recent call last): 
    File "C:\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start 
    stdout=self.log_file, stderr=self.log_file) 
    File "C:\Python36\lib\subprocess.py", line 707, in __init__restore_signals, start_new_session) 
    File "C:\Python36\lib\subprocess.py", line 990, in _execute_child 
startupinfo) 
FileNotFoundError: [WinError 2] The system cannot find the file specified 

During handling of the above exception, another exception occurred: 

Traceback (most recent call last): 
    File "C:/Users/Will Pickard/PycharmProjects/Basics/Webdriver.py", line 3, in <module> 
    driver = webdriver.Firefox() 
    File "C:\Python36\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 140, in __init__ 
self.service.start() 
    File "C:\Python36\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' executable needs to be in PATH. 

Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x03801170>> 
Traceback (most recent call last): 
    File "C:\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 173, in __del__ 
self.stop() 
    File "C:\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 145, in stop 
    if self.process is None: 
AttributeError: 'Service' object has no attribute 'process' 

答えて

1

バージョンのカップルの前に、Seleniumは、Firefoxのネイティブサポートを提供を停止し、現在制御のための外部ブラウザドライバを使用してに依存しているので。利用可能gecko webdriverをダウンロードして、次のコードを使用し

from selenium import webdriver 
ff = "/path/to/geckodriver" 
driver = webdriver.Firefox(executable_path=ff) 
0

をあなたがまたはchromedriver(ヤモリV47後にFirefoxなどのブラウザ用)(Chromeブラウザ用)geckodriverをインストールする必要があります。 インストール後、以下の設定を使用してコードを実行できるはずです。

FIREFOXとDesiredCapabilitiesを設定し、ドライバのバイナリファイルをポイントすることができます。これらの機能でドライバを設定し、必要なページを取得できるはずです。

from selenium import webdriver 
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities 

firefox_capabilities = DesiredCapabilities.FIREFOX 
firefox_capabilities['marionette'] = True 
firefox_capabilities['binary'] = '/usr/local/bin/geckodriver' 

driver = webdriver.Firefox(capabilities=firefox_capabilities) 
driver.get("http://www.python.org") 

あなたは、Firefoxの新しいバージョンが使用されていることがわからない場合は別の方法として、あなたはDesiredCapabilitiesを設定せずに、このような何かを行うことができます。

from selenium import webdriver 
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary 

driver = webdriver.Firefox(firefox_binary=FirefoxBinary('/usr/local/bin/geckodriver')) 
driver.get("http://www.python.org") 
関連する問題