Q&A
実現したいこと
補足のような解析対象のhtmlがあります。
この中の
<span class="glyphicon pull-right glyphicon-chevron-down" aria-hidden="true"></span>
は、このクラスをクリックすると、
<span class="glyphicon pull-right glyphicon-chevron-up" aria-hidden="true"></span>
と、up/downが交互に変化します。
もし、upならば、クリックして、downに変化させます。
downのときに、処理を行いたいのです。
前提
それを最初から行う前に、まず、今どちらの状態にあるかをチェックすることを行いたいと思います。
そのためのコードを試しました。
期待したことは、"up"か"down"のいずれかなのですが、実行すると"fault”になります。
原因として、
・このコードではそうなるのが必然
・tryの使い方が間違っている
・その他
のいずれかと思うのですが、経験が浅く判断できません。
なおこの箇所に至るまでは、それなりに処理できているようです。
何が原因で、どうすれば目的のことができるでしょうか。
発生している問題・エラーメッセージ
期待通りの処理でない。faultになる。
該当のソースコード
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 8from selenium.webdriver.support.select import Select 9 10driver = webdriver.Chrome("c:/driver/chromedriver.exe") 11driver.get("https://eas.forexsb.com") 12wait = WebDriverWait(driver, 10) 13 14element = wait.until(EC.element_to_be_clickable((By.ID, 'user-sign-in-email'))) 15EC.element_to_be_clickable((By.ID, 'user-sign-in-email')) 16email = driver.find_element(By.ID,"user-sign-in-email") 17email.send_keys("****@****.jp") 18elem_login_pw = driver.find_element(By.ID,"user-sign-in-password").send_keys("qACSqwvD") 19elem_login_email = driver.find_element(By.ID,"user-sign-in-submit").send_keys("keys.ENTER") 20 21 22elm_confirm=wait.until(EC.element_to_be_clickable((By.ID,'eas-main-accept-legal'))) 23elm_confirm.click() 24#element.send_keys("keys.ENTER") 25 26print("confirm ok") 27time.sleep(2) 28 29elm_generator=driver.find_element(By.ID,"acquisition-link"); 30elm_generator.click() 31 32print("generator") 33 34########## 以下が問題の箇所です ######## 35 36time.sleep(5) 37 38xpath = "/div/h4//div/div/h4/a/span" 39try: 40 elm_updown = driver.find_element(By.CLASS_NAME("glyphicon.pull-right.glyphicon-chevron-up")) 41 print("up") 42except: 43 try: 44 elm_updown = driver.find_element(By.CLASS_NAME("glyphicon.pull-right.glyphicon-chevron-down")) 45 46 print("down") 47 except: 48 print("fault") 49 50
試したこと
この問題個所については特になし
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
解析対象部分のHTMLコード
<div class="panel-group" id="settings-container"> <h4>Generate new strategies</h4> <div class="panel panel-default"> <div class="panel-heading"> <h4 class="panel-title"> <a data-toggle="collapse" data-parent="#settings-container" href="#collapse1">1. Historical data</a> <span class="glyphicon pull-right glyphicon-chevron-down" aria-hidden="true"></span> </h4> </div> <div class="panel-collapse collapse" id="collapse1"> <div class="panel-body"> <form class="form-horizontal form-no-submit" autocomplete="off" style="margin-bottom: 30px;"> <div class="form-group">
対象サイト
https://expert-advisor-studio.com/
trialであれば、自由に使えます。
python 3.8.11
selenium 4.11
chrome使用
パネル1、パネル2、パネル3のスクリーンショット
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
2023/04/01 23:44
2023/04/02 03:01
2023/04/02 05:09
2023/04/02 08:36