I would set driver
in this function to any web-driver the user may using, through it’s quite hard, Because lots of different web-drivers are be used.
Here’s code.
from selenium import webdriver
def login() -> dict:
driver = webdriver.ChromiumEdge()
driver.get("https://an.url")
cookies = None
while cookies == None:
cookies = driver.get_cookie("COOKIES")
if cookies != None:
cookies = {cookies["name"]: cookies["value"]}
driver.close()
break
return cookies
I found that when I used driver = selenium.webdriver.Safari()
(There’s NO Safari in Windows), it raised selenium.common.exceptions.NoSuchDriverException
. I tried to write all web-driver into a list then check if they could raise this exception. However it not happend. It just got stuck. Error log of NoSuchDriverException
below.
>>> from selenium import webdriver
>>> driver = webdriver.Safari()
Traceback (most recent call last):
File "C:UsersAdministratorAppDataLocalProgramsPythonPython312Libsite-packagesseleniumwebdrivercommondriver_finder.py", line 67, in _binary_paths
output = SeleniumManager().binary_paths(self._to_args())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:UsersAdministratorAppDataLocalProgramsPythonPython312Libsite-packagesseleniumwebdrivercommonselenium_manager.py", line 54, in binary_paths
return self._run(args)
File "C:UsersAdministratorAppDataLocalProgramsPythonPython312Libsite-packagesseleniumwebdrivercommonselenium_manager.py", line 126, in _run
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: Unsuccessful command executed: C:UsersAdministratorAppDataLocalProgramsPythonPython312Libsite-packagesseleniumwebdrivercommonwindowsselenium-manager.exe --browser safari --language-binding python --output json; code: 65
{'code': 65, 'message': 'safaridriver not available for download', 'driver_path': '', 'browser_path': ''}
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:UsersAdministratorAppDataLocalProgramsPythonPython312Libsite-packagesseleniumwebdriversafariwebdriver.py", line 48, in __init__
self.service.path = DriverFinder(self.service, options).get_driver_path()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:UsersAdministratorAppDataLocalProgramsPythonPython312Libsite-packagesseleniumwebdrivercommondriver_finder.py", line 50, in get_driver_path
return self._binary_paths()["driver_path"]
^^^^^^^^^^^^^^^^^^^^
File "C:UsersAdministratorAppDataLocalProgramsPythonPython312Libsite-packagesseleniumwebdrivercommondriver_finder.py", line 78, in _binary_paths
raise NoSuchDriverException(msg) from err
selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for safari; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location
Cooooldwind_ is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.