0
0

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 1 year has passed since last update.

selenium ver.4を使う

Last updated at Posted at 2023-08-03

久しぶりにseleniumを使ったら、かなり沼ったので、使い方を記す

実行環境

OS Windows 11
python 3.10.11
selenium 4.11.2
Google Chrome canary 117.0.5926.0

環境構築

pip install selenium
Google Chrome canaryは検索してダウンロード

下記のコードを保存した場所と同じところに
クロームのドライバを保存
chromedriver.exe

ドライバの探し方は最新版 ChromeCanary の ChromeDriver を取得する方法を参照

正常に動作したコード

ほぼSeleniumのドキュメントに近いです

from selenium import webdriver
import time

driver = webdriver.Chrome()
driver.get('https://www.google.co.jp/')
time.sleep(5)

driver.quit()

正常に動作しなかったコード

from selenium import webdriver
import chromedriver_binary
import time

driver = webdriver.Chrome()
driver.get('https://www.google.co.jp/')
time.sleep(5)

driver.quit()

chromedriver_binaryをインポートしてはいけません
エラーが出て、Chromeが起動しませんでした

find_element_by_idも使えなくなあったので解決策はこちら
AttributeError: 'WebDriver' object has no attribute 'find_element_by_id' の解決策

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?