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

Headless broke #2083

Open
MateusSanchesRodriguez opened this issue Nov 15, 2024 · 1 comment
Open

Headless broke #2083

MateusSanchesRodriguez opened this issue Nov 15, 2024 · 1 comment

Comments

@MateusSanchesRodriguez
Copy link

when I run my code with headless turned off it works perfectly, but when I run it with headless it can't find the elements, I asked it to save the html of the page that headless is locking and it returns to the captcha page, so I assume it's not managing to solve the captcha in headless mode, does anyone have a solution?

options = uc.ChromeOptions()
# options.add_argument('--no-sandbox') # Bypass OS security model
# options.add_argument('--disable-dev-shm-usage') # Overcome limited resource problems
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--disable-gpu') # Adicione esta linha
#options.add_argument('--headless')
brave_path = r'C:\Users\Teste\hml\selenium\Brave-Browser\Application\brave.exe'
options.binary_location = brave_path

driver = uc.Chrome(options=options)



driver.get('https://www.emailnator.com/')
time.sleep(30)

try:
    driver.find_element('xpath', '//*[@id="custom-switch-domain"]').click()
    print("Clique no botão de login realizado com sucesso!")
except Exception as e:
    html_content = driver.page_source
    # Salva o HTML em um arquivo
    with open("pagina_salva.html", "w", encoding="utf-8") as file:
        file.write(html_content)
        print("HTML da página foi salvo em 'pagina_salva.html'.")

    # Fecha o driver após a execução
    driver.quit()
    print("Erro ao clicar no botão:")
driver.find_element('xpath', '//*[@id="custom-switch-plusGmail"]').click()
@mdmintz
Copy link

mdmintz commented Nov 15, 2024

I patched headless mode of Undetected Chromedriver and NoDriver into https://github.com/seleniumbase/SeleniumBase.
(See the UC Mode and CDP Mode docs.)
Lots of updates, such as an ad-block option, etc.
Here's a script for headless mode: (After pip install seleniumbase)

from seleniumbase import SB

with SB(uc=True, test=True, headless=True, ad_block=True) as sb:
    url = "https://www.browserscan.net/bot-detection"
    sb.activate_cdp_mode(url)
    sb.cdp.flash("Test Results")
    sb.cdp.assert_element('strong:contains("Normal")')
    sb.sleep(0.5)
    sb.cdp.save_screenshot("bscan.png")

bscan

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

2 participants