title: Wait for XHR Request and/or a Console message for Selenium in Python
body: <p>I'm trying to make selenium capture the page source after it has fully rendered, if I go to the page and capture straight away only a bit of the page has rendered, if I put in a sleep of 30 seconds it fully renders but I want it to be more efficient.</p>
  
  <p>If we use <a href="https://twitter.com/i/notifications" rel="nofollow noreferrer">https://twitter.com/i/notifications</a> as an example, you'll see that after 5~ seconds after the page loads there is a toast_poll and a timeline XHR request.</p>
  
  <p>I want to be able to detect one of these requests and wait until one fires, then that is an indicator that the page has loaded fully.</p>
  
  <p>The site that I am using fires <code>console.log("Done")</code> so if I could detect the console commands in PhantomJS &amp; Firefox then this would be an even better choice than waiting for an XHR request, just wait until <code>Done</code> appears in the console and then that is the indicator that the page has loaded fully.</p>
  
  <p><strong>Regarding the Duplicate Flagging of this Post:</strong></p>
  
  <p>This question is in regards to PhantomJS and Firefox, the post <a href="https://stackoverflow.com/questions/28678872/detect-javascript-console-output-with-python">Detect javascript console output with python</a> is from over a year ago and the answer given only works on Chrome, I am looking for a <code>PhantomJS</code> and <code>Firefox</code> option, which I already think based on StackOverflow isn't possible so that's why my start of my post is about waiting for an XHR request.</p>
  
  <p>I've already tried the following code, but it doesn't work for me.. I get zero response even though the website is throwing a console.log("Done")</p>
  
  <pre><code>from seleniumrequests import PhantomJS
  from seleniumrequests import Firefox
  from selenium import webdriver
  import os
  
  webdriver.DesiredCapabilities.PHANTOMJS['phantomjs.page.customHeaders.User-Agent'] = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/37.0.2062.120 Chrome/37.0.2062.120 Safari/537.36'
  webdriver.DesiredCapabilities.PHANTOMJS['loggingPrefs'] = { 'browser':'ALL' }
  
  browser = PhantomJS(executable_path="phantomjs.exe", service_log_path=os.path.devnull)
  browser = webdriver.Firefox()
  browser.set_window_size(1400, 1000)
  
  url = "https://website.com"
  browser.get(url)
  
  for entry in browser.get_log('browser'):
      print entry
  </code></pre>
  
  <p>I'm unable to test with <code>browser = webdriver.Firefox()</code> commented out because I am not sure how to have two lots of <code>DesiredCapabilities</code> set.</p>