3
1

3.selenium4以降のエラーについて

Last updated at Posted at 2023-12-07

3.selenium4以降のエラーについて

selenium3で使用可能だった一部のメソッドについて、selenium4では警告or廃止(エラー)になるため、下記にまとめます。

・目次
3.1.警告機能
 3.1.1.executable_path
3.2.廃止機能
 3.2.1.find_element_by_~





3.1.警告機能
executable_path:以下発生
 TypeError: init() got multiple values for argument 'options'

対策:

Python.
webdriver.Chrome(ChromeDriverManager.install(), options=options)

↓ selenium4.5以前

Python.
service = Service(executable_path=ChromeDriverManager().install())
webdriver.Chrome(options=options, service=service)

↓ selenium4.6以降(2022/11/4 リリース)
 ※自動取得に変更された

Python.
from selenium import webdriver
driver = webdriver.Chrome()



3.2.廃止機能
find_element_by_:以下発生
 AttributeError: 'WebDriver' object has no attribute find_element_by_css_selector'

selenium4.3.0(selenium4)で廃止された機能(2021/10/13 リリース)

対策:

Python.
browser.find_element_by_css_selector("cssselector")
browser.find_element_by_class_name("classname") 
browser.find_element_by_xpath("xpath") 
browser.find_element_by_LINK_TEXT("by_LINK_TEXT")

Python.
browser.find_element(By.css_selector, "cssselector")
browser.find_element(By.class_name, "classname") 
browser.find_element(By.xpath, "xpath") 
browser.find_element(By.LINK_TEXT, "by_LINK_TEXT")



以上!

3
1
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
3
1