LoginSignup
demilio
@demilio

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!

AttributeError: 'list' object has no attribute 'send_keys'

解決したいこと

エラーを解決したい

動画コンテンツでPythonを使用しスクレイピングの勉強をしています。
動画通りにやると以下のエラーが表示されました。
調べてもわからなかったのでどなたか教えていただきたいです。

Windows 11
Jupyter lab

該当するソースコード

text_box = driver.find_elements(By.NAME,'text_word')
text_box.send_keys('Pythonプログラミング')

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

AttributeError                            Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_2736\415384786.py in <module>
      1 text_box = driver.find_elements(By.NAME,'text_word')
----> 2 text_box.send_keys('Pythonプログラミング')

AttributeError: 'list' object has no attribute 'send_keys'
0

1Answer

「find_element」に変更することでうまくいかないでしょうか?

- text_box = driver.find_elements(By.NAME,'text_word')
+ text_box = driver.find_element(By.NAME,'text_word')

エラーにある通り「find_elements」だとリストで返ってきます。
以下のように「取ってこれた要素の何番目か」を指定するだけでも動くと思います。

text_boxes = driver.find_elements(By.NAME,'text_word')
text_boxes[0].send_keys('Pythonプログラミング')
0Like

Comments

  1. @demilio

    Questioner
    ご回答ありがとうございます。
    回答していただいた内容を試させていただきましたが、うまくいきませんでした。
    他に考えられることはありますでしょうか。
  2. 2点確認ですが、

    ①エラーの内容は変わらずでしょうか?
    ②send_keysを呼び出す前に、正しく要素が取得できているかは確認できていますでしょうか?
  3. @demilio

    Questioner
    エラーの内容変わっていました。
    2点を確認したところ無事解決致しました。

    ありがとうございます。

Your answer might help someone💌