title: Click 'onclick' button with selenium and Python
body: <p>I need to scrap some information from this <a href="https://www.24dolores.pl/pl/ogloszenia-towarzyskie" rel="nofollow">page</a>.</p>
  
  <p>However, the page needs the age confirmation before entering it. It has a button which must be clicked before the page can be seen. My problem is that my methods to click this button simply does not work. </p>
  
  <p>Im using selenium and Python 2.7.10.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>def download_specific_page(url):
      try:
          browser = get_browser()
          wait = WebDriverWait(browser, 30)
          browser.get(main_page_url)
          time.sleep(2)
          buttons = browser.find_elements_by_class('close')
          for button in buttons:
              onclick_text = button.get_attribute('onclick')
              if onclick_text and re.search('ConfirmAge();', onclick_text):
                  print "found it!"
                  button.click()
          browser.get(url)
          html = browser.page_source
          browser.close()
          return html
      except Exception:
          info = 'Generic exception\n'
          return ""
  </code></pre>
  
  <p>I also tried with xpath, but still, no success:</p>
  
  <pre><code>def download_specific_page(url):
      try:
          browser = get_browser()
          wait = WebDriverWait(browser, 30)
          browser.get(main_page_url)
          button = browser.find_element_by_xpath("/html/body/div#bg_image/div.container/div#content/div#confirmage/div.confirmage_navigation/button.close[1]")
          button.click()
          time.sleep(2)
          browser.get(url)
          html = browser.page_source
          browser.close()
          return html
      except Exception:
          info = 'Generic exception\n'
          return ""
  </code></pre>
  
  <p>Any ideas how to click this button so I can scrap the page?</p>