title: Getting elements from a Javascript pop up window in Selenium
body: <p>I am using Selenium to scrape results from an online database. However, once I have selected my results and go to export them a pop-up window appears. Normally I would just switch the frame to this window but it appears to be javascript generated. While there are elements on this pop up, the specific name keeps changing. So for instance there is a submitButton id tag. However, it is alway appended with a different ending. So for instance it will be  id="submitButton_15bb0b69431" but the next time it will be something completely different such as id="submitButton_15bb0c03e8e". My normal method of finding by ID or CSS or XPATH, therefore, does not work.</p>
  
  <p>How can I handle this window to select the elements I need? Could I perhaps somehow get the page source for the popup?</p>
  
  <p>The code I have so far is as follows:</p>
  
  <pre><code>for i in listofpa:
  try:
      driver.find_element_by_xpath(i).click()
  
      driver.find_element_by_css_selector('#mainContentRight &gt; div.pagination &gt; ul &gt; li:nth-child(13) &gt; a').click()
  
  except:
      pass
  </code></pre>
  
  <h1>This is the part I am stuck on</h1>
  
  <pre><code>time.sleep(5)
  window_before = driver.window_handles[0]
  driver.find_element_by_id("tsMore").click()
  try:
      driver.find_element_by_css_selector('#saveExportLink_6').click()
      window_after = driver.window_handles[1]
      driver.switch_to_window(window_after)
      html = driver.page_source()
      print html
  </code></pre>