title: Error selenium.common.exceptions.JavascriptException: Message: ReferenceError: room is not defined
body: <p>I was trying to automate a web based API (haxball api) using python and selenium
  there were two steps </p>
  
  <ol>
  <li><p>After visiting <a href="https://html5.haxball.com/headless" rel="nofollow noreferrer">https://html5.haxball.com/headless</a> using your browser console <kbd>F12</kbd> button and execute this <code>var room = window.HBInit({ roomName: 'botts', maxPlayers: 16 });</code>.
  After executing a captcha will appear we have to solve it manually.</p></li>
  <li><p>After  solving you have to execute another script <code>room.getPlayerList();</code> 
  it will return an array back.</p></li>
  </ol>
  
  <p>When I manually (using browser and console) do both steps, it works perfectly, but when I automate as using the code below (solving captcha manually at the 15 second interval) it is giving an error after the 15 second wait time (7th line).</p>
  
  <pre><code>from selenium import webdriver
  import time
  driver=webdriver.Firefox()
  driver.get("https://html5.haxball.com/headless")
  time.sleep(5)
  driver.execute_script("var room = window.HBInit({ roomName: 'botts', maxPlayers: 16 });")
  time.sleep(15)
  driver.execute_script("room.getPlayerList();")
  </code></pre>
  
  <p>The first Javascript executes fine but the second <code>driver.execute_script("room.getPlayerList();")</code> gives an error:</p>
  
  <blockquote>
    <p>"selenium.common.exceptions.JavascriptException: Message: ReferenceError: room is not defined"</p>
  </blockquote>
  
  <p>but both the Javascript commands execute successfully when I enter them through the browser console one by one.</p>