Q&A
実現したいこと
pythonーselenium4で、ドロップダウンリストを選択制御したい。
前提
補足に開示した、あるwebページのHTML中の<select>・・・</select>で表示されているドロップダウンリストから1個の選択を
seleniumのselect_by_valueで選択するコードを書きましたが、
実行結果に示した、 object has no attribute のエラーがでます。
比較的新しそうな参考サイトを見る限り、このコードでよさそうに見えるので、原因がわかりません。いろんなサイトを見ましたが、seleniumのバージョンが適切かどうかで紛らわしいです。
発生している問題・エラーメッセージ
AttributeError: 'WebElement' object has no attribute 'select_by_value'
該当のソースコード
念のため全部掲示します。
python
1import time 2#selenium ver 4.8.2 3from selenium import webdriver 4from selenium.webdriver.common.by import By 5from selenium.webdriver.support.ui import WebDriverWait 6from selenium.webdriver.support import expected_conditions as EC 7from selenium.common.exceptions import TimeoutException 8 9driver = webdriver.Chrome("c:/driver/chromedriver.exe") 10driver.get("https://eas.forexsb.com") 11wait = WebDriverWait(driver, 10) 12 13element = wait.until(EC.element_to_be_clickable((By.ID, 'user-sign-in-email'))) 14EC.element_to_be_clickable((By.ID, 'user-sign-in-email')) 15email = driver.find_element(By.ID,"user-sign-in-email") 16email.send_keys("***@***.jp") 17elem_login_pw = driver.find_element(By.ID,"user-sign-in-password").send_keys("qACSqwvD") 18elem_login_email = driver.find_element(By.ID,"user-sign-in-submit").send_keys("keys.ENTER") 19 20elm_confirm=wait.until(EC.element_to_be_clickable((By.ID,'eas-main-accept-legal'))) 21elm_confirm.click() 22#element.send_keys("keys.ENTER") 23 24print("confirm ok") 25time.sleep(2) 26 27elm_generator=driver.find_element(By.ID,"acquisition-link"); 28elm_generator.click() 29 30print("generator") 31 32time.sleep(2) 33 34elm_symbol=driver.find_element(By.ID,"data-symbol-control") 35elm_symbol.select_by_value('EURJPY') 36#elm_symbol.select_by_visible_text('EURJPY') 37 38print("symbol") 39 40elm_period=driver.find_element(By.ID,"data-period-control") 41elm_period.select_by_visible_text('M30') 42 43print("period") 44 45input() 46
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
実行結果
c:\python>python test3.py
c:\python\test3.py:9: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Chrome("c:/driver/chromedriver.exe")
DevTools listening on ws://127.0.0.1:61104/devtools/browser/5e1055c5-444a-4930-a72b-7f7d11260ecd
confirm ok
generator
Traceback (most recent call last):
File "c:\python\test3.py", line 36, in <module>
elm_symbol.select_by_value('AUDCAD')
^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'WebElement' object has no attribute 'select_by_value'
参考サイト
https://www.selenium.dev/ja/documentation/webdriver/support_features/select_lists/
バージョン
python 3.11.1
selenium 4.8.2
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2023/03/26 11:18