Reputation: 13
I'm trying to emulate a search using Python and Selenium, but recently I faced a problem, when a button is generated but a JS. Here, in the picture below, the button Im t rying to click is "Save..." and it is visible (and clickable) after search is finished. Using code analyzer in Firefox, I found that this button's code is:
<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>
But in this code there are two more buttons with the same text label:
<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>
I tried to click it using two different pieces of code:
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()
And another one:
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()
But neither of them seems to work. how can I overcome this situation and finally click this button?
Upvotes: 1
Views: 799
Reputation: 6398
try the following code:
Using WebDriverWait: (helps to avoid sleep in case of slow loading)
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()
Without WebDriverWait:
driver.find_element_by_xpath("//div[@class='pharmit_bottomloaders pharmit_nowrap']/button[2]/span").click()
Upvotes: 1