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.

【Python】【Selenium4】「'WebDriver' objects has no attribute 'find_element_by_name'」エラーが出た時の解消法

Posted at

背景

以下を実行した

$ python {ファイル名}.py

すると

Traceback (most recent call last):
  File "/〜/sele-tu.py", line 11, in <module>
    search_box = driver.find_element_by_name('q') #ページ上の要素の取得
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'WebDriver' object has no attribute 'find_element_by_name'

おや…?

どうやらSeleniumがVer.3 → 4 に上がる際に使えなくなった模様。

以下で解決しました。

変更前

search_box = driver.find_element_by_name('q') #ページ上の要素の取得

引数にまとめて書くやり方に統一される

変更後

from selenium.webdriver.common.by import By
search_box = driver.find_element(By.NAME, "q")

これでOK

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?