2017-01-07 5 views
1

PythonとSeleniumを使用して検索をエミュレートしようとしていますが、最近ボタンが生成されたときに問題が発生しました。ここでは、下の図でクリックするボタンは「保存...」で、検索が終了すると表示(クリック可能)されます。 Firefoxでコードアナライザを使用して、私は、このボタンのコードがあることがわかった。Pythonを使用してSeleniumで表示されたボタンをクリック

<div class="pharmit_minbottom"> 
    <button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button"> 
    <span class="ui-button-text-only"> 
    Save... 
    </span> 
    </button> 
    </div> 

しかし、このコードでは、同じテキストラベルを持つ2つの以上のボタンがあります。

<div class="pharmit_resfooter"> 
    <div class="pharmit_bottomloaders pharmit_nowrap"> 
    <button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-disabled ui-state-disabled ui-button-text-only" disabled="" role="button"> 
    <span class="ui-button-text"> 
    Minimize 
    </span> 
    </button> 
    <button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-disabled ui-state-disabled ui-button-text-only" disabled="" role="button"> 
    <span class="ui-button-text"> 
    Save... 
    </span> 
    </button> 
    </div> 
</div> 

は、私は2つを使用して、それをクリックしてみましたコードの異なる部分:

time.sleep(30) #wait for the search to finish 
driver.find_element_by_class_name('ui-button.ui-widget.ui-state-default.ui-corner-all.ui-button-text-only').click() 

そしてもう一つ:

wait = WebDriverWait(driver, 30) 
wait = wait.until(EC.element_to_be_clickable((By.CLASS_NAME,'ui-button.ui-widget.ui-state-default.ui-corner-all.ui-button-text-only'))) 
wait.click() 

しかしどちらもうまくいかないようです。この状況をどのように克服し、最後にこのボタンをクリックすることができますか?

enter image description here

答えて

0

次のコードを試してみてください。WebDriverWaitなければ(遅いロードの場合には睡眠を避けるために役立ちます)

wait = WebDriverWait(driver, 30) 
saveButton = wait.until(EC.element_to_be_clickable((By.XPATH,"//div[@class='pharmit_‌​bottomloaders pharmit_nowrap']/button[2]/span"))) 
saveButton.click() 

:WebDriverWaitを使用して

driver.find_element_by_xpath("//div[@class='pharmit_‌​bottomloaders pharmit_nowrap']/button[2]/span").click() 
+0

返信いただきありがとうございますが、このボタンはまだ読み込まれていないため、まだ 'ElementNotVisibleException'が表示されています。たぶん、私は何らかの形でドライバを検索して新しいページを取得する必要がありますか? –

+0

常に 'WebDriverWait'ソリューションを使用してください。最初の解決策を使用する際のエラーは何ですか? TimeOutException? –

+0

はい、TimeOutExceptionです。 –

関連する問題