How to integrate selenium with Replit

Question: I have some errors when I run my file and it won’t let met use selenium with replit

from selenium import webdriver
from selenium.webdriver.chrome.options import Options



chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')

driver = webdriver.Chrome(options=chrome_options)


driver.get("https://www.google.com/")

yes I do have both of these in the replit.nix file:

  • pkgs.chromium
  • pkgs.chromedriver

the error:

/chromedriver might not be compatible with the detected chrome version (116.0.5845.96); currently, chromedriver 116.0.5845.96 is recommended for chrome 116.*, so it is advised to delete the driver in PATH and retry

I did delete the path from my directory but it still shows this error

Would appreciate any help.

if this doesn’t work for you, please link a minimal repl which reproduces the issue:

2 Likes

downgrading the version worked for me, I appreciate you.

Though it is doing it all headless, is there a way to not make it headless so i can view the automation?

it shouldn’t be headless without you passing the argument. Open a new tab for the “Output” tool. If it still doesn’t work, try after running in Shell

pkill -1 Xvnc

hey,

I think there is a problem with my output window, it was loading indefinitely, either way I will have a look at it later

I do have a question regarding selenium:
im trying to see if theres a specific element on a website which tells me if an account is public or private.

I tried adding try/except but selenium still threw an error when it couldn’t access that element. Then, I tried this piece of code and it still says that the element couldn’t be found. Is there a way to see if a specific element is accessible without it throwing errors?

is_pub = driver.find_element(By.XPATH, '/html/body/div[2]/div/div/div[2]/div/div/div/div[1]/div[1]/div[2]/div[2]/section/main/div/header/div/div/span/img').is_enabled()
  print(f"is public: {is_pub}")

EAFP. See what exception is raised (the bit before the : at the final line of the error). Import that exception, and use try-except to handle it

1 Like

well I can’t even run it anymore, but i will try it whenever I find a solution. thanks boss

peep at this → 'SSL Certificates expired' -- using discordpy and selenium

Here is the current problem…

code:

try:
      
    image = driver.find_element(By.XPATH, '/html/body/div[2]/div/div/div[2]/div/div/div/div[1]/div[2]/section/main/div/header/div/div/span/img')
    print(" public account")
  except:
      
    image = driver.find_element(By.XPATH, '/html/body/div[2]/div/div/div[2]/div/div/div/div[1]/div[2]/section/main/div/header/div/div/div/button/img')
    print(' private account')

and it comes up with this error:

Traceback (most recent call last):
  File "main.py", line 89, in ban
    image = driver.find_element(By.XPATH, '/html/body/div[2]/div/div/div[2]/div/div/div/div[1]/div[2]/section/main/div/header/div/div/span/img')
  File "/home/runner/Banner/.pythonlibs/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 740, in find_element
    return self.execute(Command.FIND_ELEMENT, {"using": by, "value": value})["value"]
  File "/home/runner/Banner/.pythonlibs/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 346, in execute
    self.error_handler.check_response(response)
  File "/home/runner/Banner/.pythonlibs/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[2]/div/div/div[2]/div/div/div/div[1]/div[2]/section/main/div/header/div/div/span/img"}

File "/home/runner/Banner/.pythonlibs/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 346, in execute
    self.error_handler.check_response(response)
  File "/home/runner/Banner/.pythonlibs/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div[2]/div/div/div[2]/div/div/div/div[1]/div[2]/section/main/div/header/div/div/div/button/img"}
  (Session info: chrome=114.0.5735.106); For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors#no-such-element-exception
Stacktrace:

help would be appreciated man because for some reason this try/except works when i run it off of my pc but not from replit for some reason. I have also tried adding “except NoSuchElementException:” but it still didn’t work