How to resolve 'Process unexpectedly closed with status 11' for Selenium in IPython?

Viewed 5913

I run the following code in IPython (from official Python extension VSCode):

# %%
from selenium import webdriver

driver = webdriver.Firefox(
    executable_path='.driver/geckodriver')

It gives me the following errors:

  • For GeckoDriver 0.28.0
WebDriverException: Message: Process unexpectedly closed with status 11
  • For GeckkoDriver 0.27.0:
WebDriverException: Message: invalid argument: can't kill an exited process

My setup:

Firefox: 82.0
GeckoDriver: 0.28.0
Selenium: 3.141.0
IPython: 7.19.0
Ubuntu: 20.10
Python3 venv

Note: This script works in terminal but not IPython

Thank you.

2 Answers

I had the same issue with Firefox driver and I change it to Chrome driver it works well now

# install chromium, its driver, and selenium
!apt update
!apt install chromium-chromedriver
!pip install selenium

# set options to be headless, ..
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')

# open it, go to a website, and get results
wd = webdriver.Chrome(options=options)
wd.get("https://www.website.com")

print(wd.page_source)  # results

According to your description, I installed the same configuration as yours on my computer. When I run the code in the .py file and .ipynb file in VSCode, the result can be displayed:

enter image description here

enter image description here

It is recommended that you check the following aspects:

  1. Make sure that the kernel "ipykernel" required by Jupyter has been installed in your currently selected VSCode environment.

  2. Please check the execution path of "geckodriver" in the code.

  3. Please try to reload VSCode or restart VSCode or even your computer if conditions permit.

Related