1

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?

enter image description here

1 Answer 1

1

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()
Sign up to request clarification or add additional context in comments.

11 Comments

Thanks for the replie, but Im still getting 'ElementNotVisibleException' as this button is not even loaded. Maybe, I need to somehow get my new page after perfoming search to the driver itself?
Always use WebDriverWait solution. what is the error with using first solution? TimeOutException?
Yep, TimeOutException.
what's your observation? Does the element is displayed? or not displayed? when the exception raised? If not displayed, then increase the timeout from 30 to 60 seconds.
It is displayed even after 15 seconds and I can manually click on it. But the program thinks that it is still invisible.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.