Open ramez121 opened 1 year ago
The same problem.
options = uc.ChromeOptions()
options.headless = False
driver = uc.Chrome(options=options,version_main=116)
driver.get("https://google.com")
try this one
Selenium 4.13 does not support headless methods, it's why you got this error message:
undetected_chromedriver\__init__.py", line 398, in __init__
if headless or options.headless:
AttributeError: 'ChromeOptions' object has no attribute 'headless'
options = uc.ChromeOptions() options.headless = False driver = uc.Chrome(options=options,version_main=116) driver.get("https://google.com")
try this one
thanks man
options = uc.ChromeOptions() options.add_argument('--headless') driver = uc.Chrome(options=options,version_main=116)
driver.get("https://google.com")
For anyone still having problems, you can still downgrade to selenium 4.12.0:
pip uninstall selenium
and then
pip install selenium==4.12.0
Will try downgrading Selenium.
FWIW, I get this error even though I'm not explicitly using headless. I am using a bunch of flags, see below, and the StackOverflow posts explaining the source of each option. One of those must be setting headless, but I'm not sure which one.
options = uc.ChromeOptions()
# https://stackoverflow.com/questions/50642308/webdriverexception-unknown-error-devtoolsactiveport-file-doesnt-exist-while-t/50725918#50725918
options.add_argument("--no-sandbox")
options.add_argument("--disable-dev-shm-usage")
# https://stackoverflow.com/questions/48450594/selenium-timed-out-receiving-message-from-renderer/49123152#49123152
options.add_argument("--start-maximized") # https://stackoverflow.com/a/26283818/1689770
options.add_argument("--enable-automation") # https://stackoverflow.com/a/43840128/1689770
options.add_argument("--no-sandbox") # https://stackoverflow.com/a/50725918/1689770
options.add_argument("--disable-dev-shm-usage") # https://stackoverflow.com/a/50725918/1689770
options.add_argument("--disable-browser-side-navigation") # https://stackoverflow.com/a/49123152/1689770
options.add_argument("--disable-gpu") # https://stackoverflow.com/questions/51959986/how-to-solve-selenium-chromedriver-timed-out-receiving-message-from-renderer-exc
driver = uc.Chrome(options=options)
Can't have this: (options.headless
) ... https://github.com/ultrafunkamsterdam/undetected-chromedriver/blob/cea80717c5a3d95ccf5c40e6e38081d5454ec7a5/undetected_chromedriver/__init__.py#L398
...due to this change in selenium
4.13.0
: https://github.com/SeleniumHQ/selenium/blob/9a6947ea4fd685b5f997415565bc5dc875a71321/py/CHANGES#L6
* remove deprecated headless methods
Here are some alternatives:
from seleniumbase import Driver
import time
driver = Driver(uc=True)
driver.get("https://nowsecure.nl/#relax")
time.sleep(6)
driver.quit()
Here's another, more advanced example with retries and clicks (using the SB()
manager):
from seleniumbase import SB
with SB(uc=True) as sb:
sb.driver.get("https://nowsecure.nl/#relax")
sb.sleep(2)
if not sb.is_text_visible("OH YEAH, you passed!", "h1"):
sb.get_new_driver(undetectable=True)
sb.driver.get("https://nowsecure.nl/#relax")
sb.sleep(2)
if not sb.is_text_visible("OH YEAH, you passed!", "h1"):
if sb.is_element_visible('iframe[src*="challenge"]'):
with sb.frame_switch('iframe[src*="challenge"]'):
sb.click("span.mark")
sb.sleep(4)
sb.activate_demo_mode()
sb.assert_text("OH YEAH, you passed!", "h1", timeout=3)
Selenium 4.13 does not support headless methods, it's why you got this error message:
undetected_chromedriver\__init__.py", line 398, in __init__ if headless or options.headless: AttributeError: 'ChromeOptions' object has no attribute 'headless'
How do I solve this error , I update the chromedriver but I still get the same problem
from fake_useragent import UserAgent
import undetected_chromedriver as uc
options = uc.ChromeOptions()
options.headless=False
ua = UserAgent()
user_agent = ua.random
print(user_agent)
prefs = {"profile.managed_default_content_settings.images": 2}
options.add_experimental_option("prefs", prefs)
options.add_argument(f'--user-agent={user_agent}')
options.add_argument("--disable-javascript")
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--disable-application-cache')
options.add_argument('--disable-gpu')
options.add_argument("--force-device-scale-factor=0.3")
options.add_argument("--high-dpi-support=0.3")
options.add_argument("--user-data-dir=/home/space/.config/google-chrome/undetected1/")
options.add_argument("--start-maximized")
driver = uc.Chrome(options=options,version_main=116)
driver.set_window_size(600,3000)
driver.execute_script("document.body.style.zoom = '10%'")
seems to have been resolved in 783b839
An error occurred: 'ChromeOptions' object has no attribute 'headless' None