title: Selenium Chrome Webdriver process Working Locally But Not On Heroku
body: <p>So I have the following Selenium Chrome Webdriver process that is working correctly locally.   Basically, when the below code is run, a purchase is made through Best Buy, and an SMS message is sent to me from my Twilio phone number indicating whether or not the purchase was successful. The variables in all-caps are already defined. I also did not include the imports. Again, the below code is making the purchase SUCCESSFULLY when run locally. This means that the SMS message that I get from my Twilio phone number contains &quot;Success!&quot; every time the following code is run locally:</p>
  <pre><code>client = Client(ACCOUNT_SID, AUTH_TOKEN)
  def runBestBuyBotLocal():
      driver = webdriver.Chrome()
      driver.get(&quot;https://www.bestbuy.com/site/spongebob-squarepants-mini-plush-styles-may-vary/6404213.p?skuId=6404213&quot;)
      wait = WebDriverWait(driver, 10)
      element = wait.until(EC.presence_of_element_located((By.XPATH, &quot;/html/body[@class='size-l']/div[@class='pl-page-content']//div[@class='container-v2']/div[@class='row v-m-bottom-g']/div[2]//div[@class='col-xs-12']/div[6]/div[@class='None']/div/div/div/button[@type='button']&quot;)))
      element.send_keys(Keys.RETURN)
      element = wait.until(EC.presence_of_element_located((By.XPATH, &quot;/html//div[@class='c-portal']/div[@role='dialog']/div[1]/div[@role='dialog']/div[@role='document']//a[@role='button']&quot;)))
      element.send_keys(Keys.RETURN)
      element = wait.until(EC.presence_of_element_located((By.XPATH, &quot;/html//div[@id='cartApp']/div[@class='page-spinner page-spinner--out']/div[@class='large-view size-l']//div[@class='fluid-large-view']//section[@class='fluid-large-view__sidebar']//button[@type='button']&quot;)))
      element.send_keys(Keys.RETURN)
      element = wait.until(EC.presence_of_element_located((By.XPATH, &quot;/html//input[@id='fld-e']&quot;)))
      element.send_keys(EMAIL)
      element = wait.until(EC.presence_of_element_located((By.XPATH, &quot;/html//input[@id='fld-p1']&quot;)))
      element.send_keys(PASSWORD)
      element = wait.until(EC.presence_of_element_located((By.XPATH, &quot;/html//div[@class='cia-app-container']/div[@class='cia-actual-full-page-wrapper lv']/section/main[@class='cia-wrapper container']//form/div[3]/button&quot;)))
      element.send_keys(Keys.RETURN)
      driver.execute_script(&quot;arguments[0].scrollIntoView(true);&quot;, WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, &quot;/html//input[@id='credit-card-cvv']&quot;))))
      element = wait.until(EC.presence_of_element_located((By.XPATH, &quot;/html//input[@id='credit-card-cvv']&quot;)))
      element.send_keys(CVV)
      driver.execute_script(&quot;arguments[0].scrollIntoView(true);&quot;, WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, &quot;/html//div[@id='checkoutApp']/div[@class='page-spinner page-spinner--out']/div[1]/div[1]//div[@class='checkout__container checkout__container-fast-track']/div[@class='checkout__col checkout__col--primary']//div[@class='button--place-order-fast-track']/button&quot;))))
      element = wait.until(EC.presence_of_element_located((By.XPATH, &quot;/html//div[@id='checkoutApp']/div[@class='page-spinner page-spinner--out']/div[1]/div[1]//div[@class='checkout__container checkout__container-fast-track']/div[@class='checkout__col checkout__col--primary']//div[@class='button--place-order-fast-track']/button&quot;)))
      element.send_keys(Keys.RETURN)
      
  try:
      runBestBuyBotLocal()
      message = client.messages \
          .create(
              body='Success!',
              from_=TWILIONUMBER,
              to=MYNUMBER
          )
  except:
      message = client.messages \
          .create(
              body='Fail! ' + traceback.format_exc(),
              from_=TWILIONUMBER,
              to=MYNUMBER
          )
  </code></pre>
  <p>The following code is the basically the same process but adapted slightly to function on Heroku remote dyno. It is a part of my Heroku web app. The below code is NOT making the purchase successfully when run on Heroku remote dyno. It is instead throwing a Timeout error on the line <code>element = wait.until(EC.presence_of_element_located((By.XPATH, &quot;/html//div[@class='c-portal']/div[@role='dialog']/div[1]/div[@role='dialog']/div[@role='document']//a[@role='button']&quot;)))</code>
  This is really weird because I have the same line in <code>runBestBuyBotLocal</code>, and when <code>runBestBuyBotLocal</code> gets is executed locally, no timeout exception gets thrown on that line, and the purchase is made successfully.
  So, because of the timeout exception being thrown, every time I run the following code on a Heroku remote dyno, I get an SMS message from my Twilio phone number containing &quot;Fail!&quot;:</p>
  <pre><code>def runBestBuyBotRemote():
      chrome_options = webdriver.ChromeOptions()
      chrome_options.binary_location = os.environ.get(&quot;GOOGLE_CHROME_BIN&quot;)
      chrome_options.add_argument(&quot;--headless&quot;)
      chrome_options.add_argument(&quot;--disable-dev-shm-usage&quot;)
      chrome_options.add_argument(&quot;--no-sandbox&quot;)
      driver = webdriver.Chrome(executable_path=os.environ.get(&quot;CHROMEDRIVER_PATH&quot;), chrome_options=chrome_options)
      driver.get(&quot;https://www.bestbuy.com/site/spongebob-squarepants-mini-plush-styles-may-vary/6404213.p?skuId=6404213&quot;)
      wait = WebDriverWait(driver, 10)
      element = wait.until(EC.presence_of_element_located((By.XPATH, &quot;/html/body[@class='size-l']/div[@class='pl-page-content']//div[@class='container-v2']/div[@class='row v-m-bottom-g']/div[2]//div[@class='col-xs-12']/div[6]/div[@class='None']/div/div/div/button[@type='button']&quot;)))
      element.send_keys(Keys.RETURN)
      element = wait.until(EC.presence_of_element_located((By.XPATH, &quot;/html//div[@class='c-portal']/div[@role='dialog']/div[1]/div[@role='dialog']/div[@role='document']//a[@role='button']&quot;)))
      element.send_keys(Keys.RETURN)
      element = wait.until(EC.presence_of_element_located((By.XPATH, &quot;/html//div[@id='cartApp']/div[@class='page-spinner page-spinner--out']/div[@class='large-view size-l']//div[@class='fluid-large-view']//section[@class='fluid-large-view__sidebar']//button[@type='button']&quot;)))
      element.send_keys(Keys.RETURN)
      element = wait.until(EC.presence_of_element_located((By.XPATH, &quot;/html//input[@id='fld-e']&quot;)))
      element.send_keys(EMAIL)
      element = wait.until(EC.presence_of_element_located((By.XPATH, &quot;/html//input[@id='fld-p1']&quot;)))
      element.send_keys(PASSWORD)
      element = wait.until(EC.presence_of_element_located((By.XPATH, &quot;/html//div[@class='cia-app-container']/div[@class='cia-actual-full-page-wrapper lv']/section/main[@class='cia-wrapper container']//form/div[3]/button&quot;)))
      element.send_keys(Keys.RETURN)
      driver.execute_script(&quot;arguments[0].scrollIntoView(true);&quot;, WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, &quot;/html//input[@id='credit-card-cvv']&quot;))))
      element = wait.until(EC.presence_of_element_located((By.XPATH, &quot;/html//input[@id='credit-card-cvv']&quot;)))
      element.send_keys(CVV)
      driver.execute_script(&quot;arguments[0].scrollIntoView(true);&quot;, WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, &quot;/html//div[@id='checkoutApp']/div[@class='page-spinner page-spinner--out']/div[1]/div[1]//div[@class='checkout__container checkout__container-fast-track']/div[@class='checkout__col checkout__col--primary']//div[@class='button--place-order-fast-track']/button&quot;))))
      element = wait.until(EC.presence_of_element_located((By.XPATH, &quot;/html//div[@id='checkoutApp']/div[@class='page-spinner page-spinner--out']/div[1]/div[1]//div[@class='checkout__container checkout__container-fast-track']/div[@class='checkout__col checkout__col--primary']//div[@class='button--place-order-fast-track']/button&quot;)))
      element.send_keys(Keys.RETURN)
  
  client = Client(ACCOUNT_SID, AUTH_TOKEN)
  try:
      runBestBuyBotRemote()
      message = client.messages \
          .create(
              body='Success!',
              from_=TWILIONUMBER,
              to=MYNUMBER
          )
  except:
      message = client.messages \
          .create(
              body='Fail!' + traceback.format_exc(),
              from_=TWILIONUMBER,
              to=MYNUMBER
          )
  </code></pre>
  <p><strong>So, the question is: does anyone have an idea as to why <code>runBestBuyBotLocal</code> is NOT throwing a timeout exception when run locally and why <code>runBestBuyBotRemote</code> IS throwing a timeout exception when run on my Heroku remote dyno? In other words, why am I getting a &quot;Success!&quot; SMS message when the process is run locally and a &quot;Fail!&quot; message when it is run on my Heroku remote dyno?</strong></p>
  <p>I'm confused why the process is succeeding when run locally and failing when run on Heroku remote dyno. The only difference between <code>runBestBuyBoyLocal</code> and <code>runBestBuyBotRemote</code> functions is how the webdriver is instantiated. So the reason for one failing and one succeeding could be due to this difference, but I'm not sure.</p>
  <p>Let me know if I need to clear up anything!</p>