Forums

Chromedriver doesn't work

I created a Telegram bot using aiogram. The bot should follow the link, take a screenshot of the page and send it to the user. But when the bot tries to start Chrome using Selenium, Chromedriver gives an error:

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
  (Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 5.8.0-1041-aws x86_64)

Here is the part of the code that is responsible for working with the browser:

async def send_screen(chat_id, url):
    import os
    from selenium import webdriver

    from loader import bot

    # Chrome launch
    options = webdriver.ChromeOptions()
    options.add_argument('--headless')
    options.add_argument('--disable-gpu')
    options.add_argument('--disable-dev-shm-usage')
    options.add_argument('--no-sandbox')
    driver = webdriver.Chrome(executable_path=r'/usr/local/bin/chromedriver', options=options)

    # sending screenshot
    driver.get(url)
    photo_path = f'img/{str(chat_id)}.png'
    driver.save_screenshot(photo_path)
    await bot.send_photo(chat_id, photo=open(photo_path, 'rb'))
    os.remove(photo_path)
    driver.quit()

Everything worked fine before. I don’t understand what the problem is?

Maybe start with the basic code that is known to work (example here: https://help.pythonanywhere.com/pages/selenium ) and start adding to that to see what makes it break.

I have a similar issue, meaning "everything worked fine before" (for over a year) and suddenly it stopped working over weekend. I thought it could have something to do with the system image upgrade ("fishnchips" to "glastonbury") which I did on Saturday. Is that possible or is it just a coincidence?

Actually, Selenium is still working but it seems to stop at a certain point, which it did not before and which it still does not on my local system (with the same code). Selenium still makes a screenshot, when the error occurs, and put it on the disk. In my case, it's just a timeout error: obisiously Selenium does not find a specific button on the page to push it.

Something else I wondered about: On the Selenium help page, you start with upgrading Selenium to the newest version (which is 4.1.0 right now, I guess). I think, before on the same page (or somewhere else) was a note to use the Version 3.141.0. So this restriction is not longer valid and it's save now to use the latest version, right?

I checked both versions in respect to my issue – it makes no difference.

If it's "just stopping", are you sure that it's just not waiting for something to happen that is not happening? It sounds like selenium and chrome are working, just not getting the things your code is looking for. That could just be a change of the site that you're accessing.

The strange thing is, that it's still working on my local computer. That's why I thought it could have something to do with the system image upgrade.

Can you confirm that using 4.1.0 is OK now?

The issue with different versions of selenium is generally that you cannot start the browser. If you are able to do that, then the version should be fine.

OK, I found the solution in my case: Obviously the line

chrome_options.add_argument("--lang=de-DE")

did not work anymore and I had to change it to something with add_experimental_option('prefs', {'intl.accept_languages':… (like seen here). I suppose, "glastonbury" has a newer chromedriver version that requires another language setting. My program could no longer find a certain text on the button because it was in English now. Locally everything is in German by default and so it still worked here, I suppose.

Anyway, I am happy now and apologize for having "hijacked" this thread.

No problem -- glad you figured that out!