title: Using Python and Selenium WebDriver to wait and click on a visible button
body: <p>I am having a torrid time trying to click on a button using Webdriver. The button is not visible until a value is entered in a prior field. I have tried adding sleeps and explicit waits but still no luck.</p>
  
  <p>I am thinking it might have something to do with page javascript, but my skills don't quite extend that far. I am still learning so apoligies for my ugly code...</p>
  
  <pre><code>count=1
  while count &lt; 3:
  time.sleep(2)
  # Not the best way to select the button - but it works for now!
  elem = driver.find_element_by_tag_name("button").click()
  #Clear default amount
  elem = driver.find_element_by_name("amount")
  elem.send_keys(Keys.BACKSPACE)
  elem.send_keys(Keys.BACKSPACE)
  elem.send_keys(Keys.BACKSPACE)
  elem.send_keys(Keys.BACKSPACE)
  elem.send_keys(Keys.BACKSPACE)
  elem.send_keys(Keys.BACKSPACE)
  elem.send_keys("0.04")
  print 'Entered Amount'
  time.sleep(1)
  elem.send_keys(Keys.TAB)
  
  time.sleep(3)
  elem.send_keys(Keys.TAB)
  
  time.sleep(3)
  elem.send_keys("\n")
  
  # This finds the button - but it isn't visible
  # elem = driver.find_element_by_tag_name("button").click()
  time.sleep(6)
  print 'Number of Payments = ', count
  count = count + 1
  print 'Finished!'
  </code></pre>
  
  <p>The website code looks like this:</p>
  
  <pre><code>&lt;button type="button" class="btn alpha centred-form-button ng-binding" ng-click="accountsPayCtrl.submit()" ng-disabled="!accountsPayCtrl.paymentSubmitted &amp;amp;&amp;amp;
            (!paymentForm.$valid || !accountsPayCtrl.inAmount || !accountsPayCtrl.payToken)" tabindex="0" aria-disabled="false"&gt;
          Pay $0.04 now
        &lt;/button&gt;
  </code></pre>
  
  <p>There are no doubt more elegant ways to get to the end result too!</p>
  
  <p>Error I am getting is:</p>
  
  <pre><code>Traceback (most recent call last):
  File "C:\MW_Test\energyaust_Explicit_Wait.py", line 43, in &lt;module&gt;
  elem = driver.find_element_by_tag_name("button").click()
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 75, in click
  self._execute(Command.CLICK_ELEMENT)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 454, in _execute
  return self._parent.execute(command, params)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 201, in execute
  self.error_handler.check_response(response)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 181, in check_response
  raise exception_class(message, screen, stacktrace)
  selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be inter
  acted with
  Stacktrace:
  at fxdriver.preconditions.visible (file:///c:/users/ozmatt/appdata/local/temp/tmpupncqr/extensions/fxdriver@googleco
  de.com/components/command-processor.js:9981)
  at DelayedCommand.prototype.checkPreconditions_ (file:///c:/users/ozmatt/appdata/local/temp/tmpupncqr/extensions/fxd
  river@googlecode.com/components/command-processor.js:12517)
  at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/ozmatt/appdata/local/temp/tmpupncqr/extensions/fxdr
  iver@googlecode.com/components/command-processor.js:12534)
  at DelayedCommand.prototype.executeInternal_ (file:///c:/users/ozmatt/appdata/local/temp/tmpupncqr/extensions/fxdriv
  er@googlecode.com/components/command-processor.js:12539)
  at DelayedCommand.prototype.execute/&lt; (file:///c:/users/ozmatt/appdata/local/temp/tmpupncqr/extensions/fxdriver@goog
  lecode.com/components/command-processor.js:12481)
  </code></pre>