I am trying to run a basic script using selenium (python) in Ubuntu 23.04 (Latest).
As I cannot use Pip in ubuntu 23.04. When I tried with pip to install selenium and webdriver Manager then this error displayed:
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.
If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.
If you wish to install a non-Debian packaged Python application,
it may be easiest to use pipx install xyz, which will manage a
virtual environment for you. Make sure you have pipx installed.
See /usr/share/doc/python3.11/README.venv for more information.
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
Then I tried with virtual Environment. I can install selenium and Webdriver Manager in Venv. But then I face a new problem, I write a basic script for firefox (Selenium-python) and Webdriver Manager:
from selenium import webdriver
from selenium.webdriver.firefox.service import Service as FirefoxService
from webdriver_manager.firefox import GeckoDriverManager
driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()))
driver.get("https://www.rokomari.com")
print(driver.title)
driver.close()
then the error is displayed:
Traceback (most recent call last):
File "/media/zahed/Project_Life/Software_Testing/Selenium/test.py", line 5, in <module>
driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/media/zahed/Project_Life/Software_Testing/Selenium/.venv/lib/python3.11/site-packages/selenium/webdriver/firefox/webdriver.py", line 201, in __init__
super().__init__(command_executor=executor, options=options, keep_alive=True)
File "/media/zahed/Project_Life/Software_Testing/Selenium/.venv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 286, in __init__
self.start_session(capabilities, browser_profile)
File "/media/zahed/Project_Life/Software_Testing/Selenium/.venv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 378, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/media/zahed/Project_Life/Software_Testing/Selenium/.venv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 440, in execute
self.error_handler.check_response(response)
File "/media/zahed/Project_Life/Software_Testing/Selenium/.venv/lib/python3.11/site-packages/selenium/webdriver/remote/errorhandler.py", line 245, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Process unexpectedly closed with status 1
Also tried with chromium webdriver:
then the choromium browser just opens but it is not loaded the website. got just blank screen scripts for chromium
Now, Can anyone help me how can actually run selenium scripts in ubuntu 23.04 for chrome and firefox.
Thanks in advance.