LoginSignup
Yog-Sothoth
@Yog-Sothoth (Ryoko Sosu)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

pythonのseleniumでスクレイピングをするとエラーが出る

解決したいこと

pythonのJupiterNotebookでのseleniumでスクレイピングをするとエラーが出てしまいます。

発生している問題・エラー

DeprecationWarning: find_element_by_* commands are deprecated. Please use find_element() instead

該当するソースコード

elem_pass = browser.find_element_by_id('inputPassword')

自分で試したこと

次の記事を参考にしてターミナルでseleniumのヴァージョンを4.3.0から4.1.0に変更しました。

それでもエラーが出たので、次の記事を参考にして次のようにコードを書き換えました。

import selenium
from selenium.webdriver.common.by import By
elem_pass = browser.find_element(BY.ID, 'inputPassword')

すると、BYが定義されていないというエラーが出てしまいました。

NameError: name 'BY' is not defined

どうすればエラーメッセージが出ずに処理できるでしょうか。

0

1Answer

スペルミスです

import selenium
from selenium.webdriver.common.by import By
- elem_pass = browser.find_element(BY.ID, 'inputPassword')
+ elem_pass = browser.find_element(By.ID, 'inputPassword')
1

Your answer might help someone💌