selenium.common.exceptions.WebDriverException

Summary

Hello there! My app of using selenium worked on localhost but on streamlit cloud, it don’t worked. Please tell me how to fix.

Steps to reproduce

Code snippet:

import streamlit as st
import os
import re
from PIL import Image
import shutil

from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
import subprocess
from webdriver_manager.chrome import ChromeDriverManager


cmd = 'pip install --upgrade chromedriver_binary' 
res = subprocess.call(cmd, shell=True) 

chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs",prefs)
chrome_options.add_argument('--headless')
driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=chrome_options)


# driver = webdriver.Chrome(executable_path=r'C:\Users\hskw1\git_space\llamaindex_ocr\chromedriver')
driver.get('https://www3.nohhi.co.jp/rktrace/trace.html')

search_bar = driver.find_element_by_name("command5")

search_bar.send_keys(num) # num is variable. order number

search_bar.submit()

Error:

2023-08-17 22:13:40.393 Uncaught app exception

Traceback (most recent call last):

  File "/home/adminuser/venv/lib/python3.11/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 552, in _run_script

    exec(code, module.__dict__)

  File "/mount/src/llamaindex_ocr/main.py", line 70, in <module>

    driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=chrome_options)

             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/adminuser/venv/lib/python3.11/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__

    self.service.start()

  File "/home/adminuser/venv/lib/python3.11/site-packages/selenium/webdriver/common/service.py", line 98, in start

    self.assert_process_still_running()

  File "/home/adminuser/venv/lib/python3.11/site-packages/selenium/webdriver/common/service.py", line 109, in assert_process_still_running

    raise WebDriverException(

selenium.common.exceptions.WebDriverException: Message: Service /home/appuser/.wdm/drivers/chromedriver/linux64/114.0.5735.90/chromedriver unexpectedly exited. Status code was: 127

Hey @kazuhiro! :wave:

Here are three examples of running Selenium on Streamlit Community Cloud:

  1. @Franky1’s example:
  1. @snehankekre’s example:
  1. @randyzwitch’s example:

I hope these suggestions will help you in identifying and debugging the issue you’re facing.

If not, please let us know, and we’ll be happy to take another look! :blush:

Thanks, Charly

1 Like

Hi Charly! Thank you for your information, I could study about the error.
My app worked on streamlit cloud. Thank you so much.

fixed code

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options

options = Options() 
options.add_argument("--headless=new")
options.add_argument('--disable-gpu')

driver = webdriver.Chrome(options=options)

driver.get('https://www3.nohhi.co.jp/rktrace/trace.html')

search_bar = driver.find_element(By.NAME, "command5")
search_bar.send_keys(num)
search_bar.submit()
1 Like

Glad it worked in the end!

Happy Streamlit-ing! :balloon:

Charly

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.