I am using Selenium with 'undetected_chrome.' However, when I update to the latest version of Selenium, which is 4.14.0, and use it with 'undetected_chrome,' I encounter the following error: 'AttributeError: 'Options' object has no attribute 'headless'.
#pip install selenium==4.14.0
#pip install undetected-chromedriver==3.5.0
from selenium import webdriver
from undetected_chromedriver import Chrome
# driver=webdriver.Chrome()
driver=Chrome()
driver.get('https://stackoverflow.com/')
input('Enter to close window')
driver.quit()
Error:
Traceback (most recent call last):
File "d:\Python\browser.py", line 8, in <module>
driver=Chrome()
^^^^^^^^
File "D:\Python\venv\Lib\site-packages\undetected_chromedriver\__init__.py", line 375, in __init__
if headless or options.headless:
^^^^^^^^^^^^^^^^
AttributeError: 'ChromeOptions' object has no attribute 'headless'
It will work if we use driver = webdriver.Chrome(), or if we downgrade the Selenium version to 4.12.0. There seems to be some issue with the latest Selenium version.
In Selenium versions 4.13.0 and later, it is necessary to explicitly provide the 'headless' option in your Chrome or browser configuration. Unlike in previous versions where it defaulted to 'False,' starting from 4.13.0, you must specify this option to use in normal mode.
from selenium import webdriver
from undetected_chromedriver import Chrome
# We have to provide headless option to make it work.
options = webdriver.ChromeOptions()
options.headless=False
driver=Chrome(options=options)
Yes, this problem is due to the change in selenium 4.13.0
This link says
"* remove deprecated headless methods"
https://github.com/SeleniumHQ/selenium/blob/9a6947ea4fd685b5f997415565bc5dc875a71321/py/CHANGES#L6
Please go through this link for complete discussion and workarounds:
https://github.com/ultrafunkamsterdam/undetected-chromedriver/issues/1584
As you said:
it will work if we use driver = webdriver.Chrome(), or if we downgrade the Selenium version to 4.12.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With