find_chrome_executable() bug
Closed this issue · 3 comments
i write script into script.py
and call it with script.php
from website (not CLI)
script.py
options = webdriver.ChromeOptions()
options.add_argument("--headless=new")
options.add_argument("--no-sandbox")
options.binary_location = "/usr/bin/google-chrome"
async with webdriver.Chrome(options=options, debug=True) as self.driver:
await self.main()
i got this error:
File "/usr/local/bin/.pyenv/versions/3.10.14/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/usr/local/bin/.pyenv/versions/3.10.14/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
return future.result()
File "/www/wwwroot/45.77.173.161/mutasi/Amuba/src/BCA/bca.py", line 59, in run
options = webdriver.ChromeOptions()
File "/usr/local/bin/.pyenv/versions/3.10.14/lib/python3.10/site-packages/selenium_driverless/types/options.py", line 52, in __init__
self._binary_location = find_chrome_executable()
File "/usr/local/bin/.pyenv/versions/3.10.14/lib/python3.10/site-packages/selenium_driverless/utils/utils.py", line 38, in find_chrome_executable
for item in os.environ.get("PATH").split(os.pathsep):
AttributeError: 'NoneType' object has no attribute 'split'
In some reason script.py
which called by script.php
can not get PATH environment. so the PATH value will be None. Which cause this problem
Note:
php => can get the PATH environment
python CLI => can get the PATH environment
python script called by php => can not get the PATH environment (idk why this is happend -_- )
i have no problem with my own script. because i still can fix it with:
if(os.environ.get('PATH') is None):
if(platform.system()=='Windows'):
os.environ["PATH"] = "" #should be Program Files and Program Files (x86) here
else:
os.environ["PATH"] = "/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"
options = webdriver.ChromeOptions()
options.add_argument("--headless=new")
options.add_argument("--no-sandbox")
options.binary_location = "/usr/bin/google-chrome"
async with webdriver.Chrome(options=options, debug=False) as self.driver:
await self.main()
The reason why open this issue is because of this code:
A. Minor Issue
above code will try to find all chrome candidates, before i put the options.binary_location
options = webdriver.ChromeOptions() # find all chrome executable candidate
options.binary_location = "/usr/bin/google-chrome" # override the candidate
async with webdriver.Chrome(options=options, debug=True) as self.driver:
await self.main()
i think we can let self._binary_location=None
first. Then we can try find candidate if self._binary_location is None
when webdriver.Chrome()
called. But if this is too complicated to fix, i think we can ignore it right now
B. Major Issue
Selenium-Driverless/src/selenium_driverless/utils/utils.py
Lines 37 to 46 in 88625e9
There is no
None
checking, so if PATH
is not found in environment , it will cause fatal error.I think that you just forgot it, because for Windows, you already have
None
checking
Thanks
@ganyu87 Thanks a lot, will definitely fix it
uhh yeah let's hope I haven't put any bug in there:)
@ganyu87 can you confirm this to be fixed now btw?