質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Chrome

Google Chromeは携帯、テレビ、デスクトップなどの様々なプラットフォームで利用できるウェブブラウザです。Googleが開発したもので、Blink (レンダリングエンジン) とアプリケーションフレームワークを使用しています。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

selenium

Selenium(セレニウム)は、ブラウザをプログラムで作動させるフレームワークです。この原理を使うことにより、ブラウザのユーザーテストなどを自動化にすることができます。

Q&A

5回答

12609閲覧

[python]seleniumでChromeDriverが強制停止する

moscow3

総合スコア201

Chrome

Google Chromeは携帯、テレビ、デスクトップなどの様々なプラットフォームで利用できるウェブブラウザです。Googleが開発したもので、Blink (レンダリングエンジン) とアプリケーションフレームワークを使用しています。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

selenium

Selenium(セレニウム)は、ブラウザをプログラムで作動させるフレームワークです。この原理を使うことにより、ブラウザのユーザーテストなどを自動化にすることができます。

0グッド

0クリップ

投稿2018/02/09 03:32

編集2022/01/12 10:55

#問題
http://chromedriver.storage.googleapis.com/index.html?path=2.9/より、ドライバーをインストールして実行したのですが、実行すると途中で強制停止します。
Windows10 64bit
python3.6.3

#状況
これに従ってコードを書いているのですが次のようなエラーが出ます。

#エラーメッセージ

python

1Traceback (most recent call last): 2 File "C:/Users/user/AppData/Local/Programs/Python/Python36-32/MyScript/SeleniumTest.py", line 11, in <module> 3 driver.get("https://www.google.co.jp/") 4 File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in get 5 self.execute(Command.GET, {'url': url}) 6 File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 306, in execute 7 response = self.command_executor.execute(driver_command, params) 8 File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 460, in execute 9 return self._request(command_info[0], url, body=data) 10 File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 484, in _request 11 resp = self._conn.getresponse() 12 File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 1331, in getresponse 13 response.begin() 14 File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 297, in begin 15 version, status, reason = self._read_status() 16 File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\http\client.py", line 258, in _read_status 17 line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") 18 File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\socket.py", line 586, in readinto 19 return self._sock.recv_into(b) 20ConnectionResetError: [WinError 10054] 既存の接続はリモート ホストに強制的に切断されました。

#ソースコード

python

1#_*_ coding: utf-8 _*_ 2 3#import json_util 4 5from selenium import webdriver 6 7import time 8 9driver = webdriver.Chrome("chromedriver_win32/chromedriver") 10 11driver.get("https://www.google.co.jp/") 12 13time.sleep(3) 14 15driver.find_element_by_id("lst-ib").send_keys("Selenium Test") 16 17driver.find_element_by_name("btnK").click() 18 19time.sleep(10) 20 21driver.quit()

32bit版しかなかったので、それを使ったことが原因かなと思うのですが、64bit版はどこにあるのでしょうか?

#追記

python

1# -*- coding: utf-8 -*- 2 3from selenium import webdriver 4from selenium.webdriver.common.keys import Keys 5 6driver = webdriver.Chrome("C:/Users/user/AppData/Local/Program/Python/Python36-32/MyScript/chromedriver_win32/chromedriver.exe") 7content = driver.find_element_by_name("q") 8content.send_keys("this is test") 9content.send_keys(Keys.ENTER) 10

エラーメッセージ

Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start stdout=self.log_file, stderr=self.log_file) File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 709, in __init__ restore_signals, start_new_session) File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 997, in _execute_child startupinfo) FileNotFoundError: [WinError 2] 指定されたファイルが見つかりません。 During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\MyScript\SeleniumTest.py", line 6, in <module> driver = webdriver.Chrome("C:/Users/user/AppData/Local/Program/Python/Python36-32/MyScript/chromedriver_win32/chromedriver.exe") File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__ self.service.start() File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\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: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2019/03/11 12:55

回答は出揃ってると思うが、いかがだろう。
guest

回答5

0

以下の環境で検証しましたが、正常に動作します。

OS : Microsoft Windows [Version 10.0.16299.192]
Python : Python 3.5.4 :: Anaconda custom (64-bit)
chrome : バージョン: 64.0.3282.140(Official Build) (64 ビット)

  • コマンドプロンプト(管理者権限)上でseleniumをインストール

DOS

1C:\WINDOWS\system32>pip install selenium 2Collecting selenium 3 Downloading selenium-3.9.0-py2.py3-none-any.whl (942kB) 4 100% |################################| 952kB 4.5MB/s 5Installing collected packages: selenium 6Successfully installed selenium-3.9.0

Python

1from selenium import webdriver 2import time 3 4driver = webdriver.Chrome("chromedriver") 5driver.get("https://www.google.co.jp/") 6time.sleep(3) 7 8driver.find_element_by_id("lst-ib").send_keys("Selenium Test") 9driver.find_element_by_name("btnK").click() 10time.sleep(10) 11driver.quit() 12 13print('OK')

ブラウザが立上り「Selenium Test」で検索されて終了。
コマンドプロンプト上の結果は以下。

PlainText

1DevTools listening on ws://127.0.0.1:12702/devtools/browser/b018b230-3ac1-4bfd-9b93-e2203bca6489 2OK

あなたの環境および行った詳細な手順を追記されると、何か分かるかもしれません。
また、社内セキュリティ上、プロキシ設定が必要な環境だと、それなりの設定コードが必要かもしれません。Selenium Chrome Proxy の設定

投稿2018/02/09 05:03

can110

総合スコア38234

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

moscow3

2018/02/09 05:40

正常に動作まではしました!  が、なぜか文字入力の後に検索されず、次のエラーが出ます。(クリックできないよ~という感じでしょうか?) Traceback (most recent call last): File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\MyScript\SeleniumTest.py", line 9, in <module> driver.find_element_by_name("btnK").click() File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click self._execute(Command.CLICK_ELEMENT) File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 501, in _execute return self._parent.execute(command, params) File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 308, in execute self.error_handler.check_response(response) File "C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: Element <input value="Google 検索" aria-label="Google 検索" name="btnK" type="submit" jsaction="sf.chk"> is not clickable at point (433, 411). Other element would receive the click: <div class="sbqs_c">...</div> (Session info: chrome=64.0.3282.140) (Driver info: chromedriver=2.35.528161 (5b82f2d2aae0ca24b877009200ced9065a772e73),platform=Windows NT 10.0.16299 x86_64)
guest

0

インストールしたChromeDriver のバージョンが2.9と古いのが原因ではないでしょうか?

2.9だとchrome のバージョンがv31-34が対応します。
----------ChromeDriver v2.9 (2014-01-31)----------
Supports Chrome v31-34

以下からChromeDriver 2.35をダウンロードしてくださいな。
Chromeを起動してアドレスにchrome://settings/help を入力するとChromeのバージョンが分かります。

投稿2018/02/09 04:36

umyu

総合スコア5846

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

moscow3

2018/02/09 04:42

それでもやっぱりうまくいきません。 Google Chrome は最新版です バージョン: 64.0.3282.140(Official Build) (64 ビット)
umyu

2018/02/09 05:00 編集

>C:\Users\user\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py のエラー行を見る限りでは64bit版ではなく32bit版のpythonで動作してませんか? Python36-32 →Python バージョン 3.6を表す36と32ビットを表す-32
umyu

2018/02/09 04:54

import sys print(sys.version) でバージョンの確認が行えます。
guest

0

お待たせしました
動作確認済みです

python

1# -*- coding: utf-8 -*- 2 3from selenium import webdriver 4from selenium.webdriver.common.keys import Keys 5 6driver = webdriver.Chrome("ドライバーの絶対パス") 7content = driver.find_element_by_name("q") 8content.send_keys("this is test") 9content.send_keys(Keys.ENTER)

大文字小文字気をつけてください

this is testと入力してエンターで検索するテストです

投稿2018/02/09 04:18

Pg_Egg

総合スコア18

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

moscow3

2018/02/09 04:33

さっそくありがとうございました。 ですが、まだエラーが出てしまいます・・ PATHが通されていないと書いてありますが、どうなんでしょう・・
moscow3

2018/02/09 04:35

なお、絶対パスを相対パスに変えたところ、実行はされますあ途中で強制停止してしまうようです
guest

0

出先でスマホで回答しているので長文が難しいです、すいません。

以前同じ状態になりました。

問題解決したテストソースを手元で見ているのですが

from selenium.webdriver.common.keys import keys

の記述がありました

結構前のことで忘れているのですが、キー操作に必要なモジュールだったような気がします

念のため試してみてください

違ったら罵ってください。

投稿2018/02/09 03:48

Pg_Egg

総合スコア18

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

moscow3

2018/02/09 04:01

from selenium import webdriverのあとに書いたところ ImportError: cannot import name 'keys' のエラーが表示されました・・・
Pg_Egg

2018/02/09 04:06

あとはドライバー指定の部分を絶対パスにして.exeまでいれてみてください。 というよりもこのまま回答が無ければソースをそのまま送るので気長にお待ちくださいな。
guest

0

32bit版しかなかったので、それを使ったことが原因かなと思うのですが、64bit版はどこにあるのでしょうか?

Python Releases for Windows ファイル名にx86-64 が含まれているのが64bit版です。

ChromeDriver - WebDriver for Chrome の ChromeDriver 2.35 では?

投稿2018/02/09 03:37

編集2018/02/09 04:10
Orlofsky

総合スコア16415

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

moscow3

2018/02/09 03:46

いえ、pythonではなくWebDriverの64bit版です (python自体は64bitで動いています)
Orlofsky

2018/02/09 04:10

回答にChromeDriverのURLを追記しました。
moscow3

2018/02/09 04:18

それがURLをクリックするとこれが表示されます。 Index of /2.35/ [ICO] Name Last modified Size ETag [DIR] Parent Directory - [DIR] chromedriver_linux64.zip 2018-01-10 02:35:57 3.55MB e6d0298d3e1ed23f6639805d13ac2ae4 [DIR] chromedriver_mac64.zip 2018-01-10 04:06:12 5.25MB 720f6f8ab16dd3fcc0d5928402ac9f92 [DIR] chromedriver_win32.zip 2018-01-10 21:19:40 3.18MB de52d0a610fb97fadc02301bc705c12b [DIR] notes.txt 2018-01-10 22:44:12 0.01MB d3bb3cea8e65d290aab9ed3d60a25d7b
Orlofsky

2018/02/09 04:23

64bit版を使いたかったら linuxかmacの環境を用意してください、ってことですね。お力になれなくてすみません。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問