1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

pythonでWebDriverを駆動

Last updated at Posted at 2019-12-17

目的

pythonでWebDriverを駆動する。
Edgeを起動できるところまでを行う。

環境構築

pythonのインストールは完了している環境で作業します。
version確認してみましたら、以下のversionでした。
Python 3.8.0

seleniumのimport

以下のコマンドを実行します。
必要であれば、管理者権限のあるコマンドラインで実行してください。

pip install selenium

pythonによる実行

seleniumがimportできたか、動作確認します。

スクリプト作成

スクリプトを作成します。

webdriver_sample.py
from selenium import webdriver

# EdgeDriver取得
driver = webdriver.Edge()
# 指定したURLに遷移する
driver.get("https://www.google.co.jp")

実行

スクリプト実行してみます。

python .\webdriver_sample.py

環境構築前ですので、エラーが発生します。

selenium.common.exceptions.WebDriverException: Message: 'MicrosoftWebDriver.exe' executable needs to be in PATH. Please download from http://go.microsoft.com/fwlink/?LinkId=619687

WebDriverへのパスが通っていないとのことですが、まだインストールしていないので、想定どおりです。

EdgeDriverのインストール

EdgeDriverのインストールをします。
以下の方法は少し古くなっています。
新しい方法に関しては、「Edge Webdriverインストール方法
」を参照して下さい。

Edgeの確認

設定→全般で確認します。
私のEdgeは以下のバージョンでした。
Microsoft EdgeHTML 18.18362

設定方法を以下のURLで確認します。
http://go.microsoft.com/fwlink/?LinkId=619687

18以降はWindows10に組み込まれていて、自動アップデートされているようです。
[開発者モード]を有効にすることで使えるようになるようです。

[開発者モード] 設定

管理者権限で設定変更します。
設定 → 更新とセキュリティ → 開発者向け
開発者モードのラジオボタンを設定します。

pythoによる実行

WebDriverが設定できたことを確認します。

Pythonで実行

スクリプト実行してみます。

python .\webdriver_sample.py

今度はブラウザ起動しました。

[開発者モード] について

一度、WebDriverインストール後であれば、[開発者モード] から元に戻しても問題ありません。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?