Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with Running non Headless #1584

Open
ramez121 opened this issue Sep 26, 2023 · 11 comments
Open

Problem with Running non Headless #1584

ramez121 opened this issue Sep 26, 2023 · 11 comments

Comments

@ramez121
Copy link

An error occurred: 'ChromeOptions' object has no attribute 'headless'
None

@Galagoshin
Copy link

The same problem.

@yudhistiramk
Copy link

yudhistiramk commented Sep 27, 2023

options = uc.ChromeOptions()
options.headless = False
driver = uc.Chrome(options=options,version_main=116)

driver.get("https://google.com")

try this one

@max32002
Copy link

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'

@BlackWolfLgt
Copy link

options = uc.ChromeOptions()
options.headless = False
driver = uc.Chrome(options=options,version_main=116)

driver.get("https://google.com")

try this one

thanks man

@Allamaris0
Copy link

options = uc.ChromeOptions()
options.add_argument('--headless')
driver = uc.Chrome(options=options,version_main=116)

driver.get("https://google.com")

@Flojomojo
Copy link

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

@cmdlinebeep
Copy link

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)

@mdmintz
Copy link

mdmintz commented Sep 27, 2023

Can't have this: (options.headless) ...

if headless or options.headless:

...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:

  • Downgrade to an earlier selenium version until fixed.
  • Use SeleniumBase's UC Mode (a modified fork of undetected-chromedriver):
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)

@Wahomethegeek
Copy link

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

@katsonis7
Copy link

katsonis7 commented Nov 9, 2023

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%'")

@dustinfarris
Copy link

seems to have been resolved in 783b839

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests