[π Bug]: Error when executing webdriver.Chrome(). Bug in selenium-manager.exe?
htykskr opened this issue Β· comments
What happened?
Error when executing webdriver.Chrome()
.
Traceback shows that a JSONDecodeError is generated.
There seems to be a problem around line 135 of selenium\webdriver\common\selenium_manager.py
.
try:
if sys.platform == "win32":
completed_proc = subprocess.run(args, capture_output=True, creationflags=subprocess.CREATE_NO_WINDOW)
else:
completed_proc = subprocess.run(args, capture_output=True)
stdout = completed_proc.stdout.decode("utf-8").rstrip("\n")
stderr = completed_proc.stderr.decode("utf-8").rstrip("\n")
I was curious, so I ran the command that selenium_manager.py
is executing in Powershell.
Command
> C:\Users\hoge\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\windows\selenium-manager.exe --browser chrome --debug --language-binding python --output json
The following results are returned, confirming that the program is running without problems.
Results
{
"logs": [
...
],
"result": {
"code": 0,
"message": "C:\\Users\\hoge\\.cache\\selenium\\chromedriver\\win64\\122.0.6261.128\\chromedriver.exe",
"driver_path": "C:\\Users\\hoge\\.cache\\selenium\\chromedriver\\win64\\122.0.6261.128\\chromedriver.exe",
"browser_path": "C:\\Users\\hoge\\.cache\\selenium\\chrome\\win64\\122.0.6261.128\\chrome.exe"
}
}
So what if run it with subprocess.run?
Codes
args = [
r'C:\Users\hoge\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\windows\selenium-manager.exe',
'--browser', 'chrome', '--debug', '--language-binding', 'python', '--output', 'json'
]
completed_proc = subprocess.run(args, capture_output=True, creationflags=subprocess.CREATE_NO_WINDOW)
print(f'command: {" ".join(args)}')
stdout = completed_proc.stdout.decode("utf-8").rstrip("\n")
stderr = completed_proc.stderr.decode("utf-8").rstrip("\n")
exit_code = completed_proc.returncode
print(f'{stdout=}')
print(f'{stderr=}')
print(f'{exit_code=}')
Results
command: C:\Users\hoge\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\windows\selenium-manager.exe --browser chrome --debug --language-binding python --output json
stdout=''
stderr=''
exit_code=3221225477
It appears that selenium-manager.exe is returning empty execution results.
How can we reproduce the issue?
from selenium import webdriver
browser = webdriver.Chrome()
browser.get('https://www.googe.com')
Relevant log output
$ python main.py
2024-03-14 10:02:49,685 - DEBUG - Selenium Manager binary found at: C:\Users\hoge\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\windows\selenium-manager.exe
2024-03-14 10:02:49,685 - DEBUG - Executing process: C:\Users\hoge\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\windows\selenium-manager.exe --browser chrome --debug --language-binding python --output json
Traceback (most recent call last):
File "C:\Users\hoge\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\selenium_manager.py", line 142, in run
output = json.loads(stdout)
^^^^^^^^^^^^^^^^^^
File "C:\Users\hoge\AppData\Local\Programs\Python\Python312\Lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\hoge\AppData\Local\Programs\Python\Python312\Lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\hoge\AppData\Local\Programs\Python\Python312\Lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\hoge\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\driver_finder.py", line 38, in get_path
path = SeleniumManager().driver_location(options) if path is None else path
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\hoge\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\selenium_manager.py", line 106, in driver_location
output = self.run(args)
^^^^^^^^^^^^^^
File "C:\Users\hoge\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\selenium_manager.py", line 145, in run
raise WebDriverException(f"Unsuccessful command executed: {command}") from err
selenium.common.exceptions.WebDriverException: Message: Unsuccessful command executed: C:\Users\hoge\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\windows\selenium-manager.exe --browser chrome --debug --language-binding python --output json
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\hoge\Work\test\main.py", line 13, in <module>
browser = webdriver.Chrome()
^^^^^^^^^^^^^^^^^^
File "C:\Users\hoge\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 45, in __init__
super().__init__(
File "C:\Users\hoge\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 49, in __init__
self.service.path = DriverFinder.get_path(self.service, options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\hoge\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\driver_finder.py", line 41, in get_path
raise NoSuchDriverException(msg) from err
selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for chrome using Selenium Manager.; For documentation on this error, please visit: https://www.selenium.dev/documentation/webdriver/troubleshooting/errors/driver_location
Operating System
Windows11
Selenium version
4.18.1
What are the browser(s) and version(s) where you see this issue?
Chrome managed by selenium manager
What are the browser driver(s) and version(s) where you see this issue?
ChromeDriver managed by selenium manager
Are you using Selenium Grid?
No response
@htykskr, thank you for creating this issue. We will troubleshoot it as soon as we can.
Info for maintainers
Triage this issue by using labels.
If information is missing, add a helpful comment and then I-issue-template
label.
If the issue is a question, add the I-question
label.
If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted
label.
If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C),
add the applicable G-*
label, and it will provide the correct link and auto-close the
issue.
After troubleshooting the issue, please add the R-awaiting answer
label.
Thank you!
Can you please share the logs after you configure the debug level?
https://www.selenium.dev/documentation/webdriver/troubleshooting/logging/
There should be much more output showing what Selenium Manager is doing. Can you please double check the link and follow the instructions?
This is the code that is running.
However, the log outputs only two lines.
Code
import logging
from selenium import webdriver
logger = logging.getLogger('selenium')
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
sh = logging.StreamHandler()
sh.setLevel(logging.DEBUG)
sh.setFormatter(formatter)
logger.addHandler(sh)
fh = logging.FileHandler(filename='./selenium.log')
fh.setLevel(logging.DEBUG)
fh.setFormatter(formatter)
logger.addHandler(fh)
browser = webdriver.Chrome()
browser.get('https://www.googe.com')
Log
2024-03-15 09:30:51,914 - DEBUG - Selenium Manager binary found at: C:\Users\hoge\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\windows\selenium-manager.exe
2024-03-15 09:30:51,914 - DEBUG - Executing process: C:\Users\hoge\AppData\Local\Programs\Python\Python312\Lib\site-packages\selenium\webdriver\common\windows\selenium-manager.exe --browser chrome --debug --language-binding python --output json
Selenium Manager's output is missing; do not send the output to a file because the Selenium Manager's log won't be sent there.
Sorry, my English is not good enough to understand it properly.
Is this what you mean by "do not send the output to a file"?
import logging
from selenium import webdriver
logger = logging.getLogger('selenium')
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
sh = logging.StreamHandler()
sh.setLevel(logging.DEBUG)
sh.setFormatter(formatter)
logger.addHandler(sh)
# fh = logging.FileHandler(filename='./selenium.log')
# fh.setLevel(logging.DEBUG)
# fh.setFormatter(formatter)
# logger.addHandler(fh)
browser = webdriver.Chrome()
browser.get('https://www.googe.com')
Yes.
I understand.
But when I run this code, the log output is still the same, just two lines.
As I told you at the beginning, the data returned by selenium-manager.exe is empty, and I think that's why the log is also not output.
Can you please grab the binary from a release and execute it locally with the same arguments your log shows?
I downloaded and ran selenium-manager-windows-debug.exe
from Release selenium-manager-573bae5.
When executed from Powershell
PS C:\Users\hoge\Work\test> ./selenium-manager-windows-debug.exe --browser chrome --debug --language-binding python --output json
{
"logs": [
{
"level": "DEBUG",
"timestamp": 1711069770,
"message": "chromedriver not found in PATH"
},
{
"level": "DEBUG",
"timestamp": 1711069770,
"message": "chrome detected at C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
},
{
"level": "DEBUG",
"timestamp": 1711069770,
"message": "Running command: wmic datafile where name='C:\\\\Program Files\\\\Google\\\\Chrome\\\\Application\\\\chrome.exe' get Version /value"
},
{
"level": "DEBUG",
"timestamp": 1711069772,
"message": "Output: \"\""
},
{
"level": "DEBUG",
"timestamp": 1711069772,
"message": "Running command: REG QUERY HKCU\\Software\\Google\\Chrome\\BLBeacon /v version"
},
{
"level": "DEBUG",
"timestamp": 1711069775,
"message": "Output: \"\""
},
{
"level": "DEBUG",
"timestamp": 1711069775,
"message": "chrome not found in the system"
},
{
"level": "DEBUG",
"timestamp": 1711069775,
"message": "Required browser: chrome 123.0.6312.58"
},
{
"level": "DEBUG",
"timestamp": 1711069775,
"message": "chrome 123.0.6312.58 already exists"
},
{
"level": "DEBUG",
"timestamp": 1711069775,
"message": "chrome 123.0.6312.58 is available at C:\\Users\\hoge\\.cache\\selenium\\chrome\\win64\\123.0.6312.58\\chrome.exe"
},
{
"level": "DEBUG",
"timestamp": 1711069775,
"message": "Required driver: chromedriver 123.0.6312.58"
},
{
"level": "DEBUG",
"timestamp": 1711069775,
"message": "chromedriver 123.0.6312.58 already in the cache"
},
{
"level": "INFO",
"timestamp": 1711069775,
"message": "Driver path: C:\\Users\\hoge\\.cache\\selenium\\chromedriver\\win64\\123.0.6312.58\\chromedriver.exe"
},
{
"level": "INFO",
"timestamp": 1711069775,
"message": "Browser path: C:\\Users\\hoge\\.cache\\selenium\\chrome\\win64\\123.0.6312.58\\chrome.exe"
}
],
"result": {
"code": 0,
"message": "C:\\Users\\hoge\\.cache\\selenium\\chromedriver\\win64\\123.0.6312.58\\chromedriver.exe",
"driver_path": "C:\\Users\\hoge\\.cache\\selenium\\chromedriver\\win64\\123.0.6312.58\\chromedriver.exe",
"browser_path": "C:\\Users\\hoge\\.cache\\selenium\\chrome\\win64\\123.0.6312.58\\chrome.exe"
}
}
When executed from subprocess.run
test.py
import subprocess
args = [
r'./selenium-manager-windows-debug.exe',
'--browser', 'chrome', '--debug', '--language-binding', 'python', '--output', 'json'
]
completed_proc = subprocess.run(args, capture_output=True, creationflags=subprocess.CREATE_NO_WINDOW)
print(f'command: {" ".join(args)}')
stdout = completed_proc.stdout.decode("utf-8").rstrip("\n")
stderr = completed_proc.stderr.decode("utf-8").rstrip("\n")
exit_code = completed_proc.returncode
print(f'{stdout=}')
print(f'{stderr=}')
print(f'{exit_code=}')
PS C:\Users\hoge\Work\test> python .\test.py
command: ./selenium-manager-windows-debug.exe --browser chrome --debug --language-binding python --output json
stdout=''
stderr=''
exit_code=3221225477
I am not sure how to proceed. We still need to see the DEBUG log level when you run this code:
from selenium import webdriver
browser = webdriver.Chrome()
browser.get('https://www.googe.com')