0

I have a bot that automates a site, I want the code to show the website for the user to solve a captcha and then switch to headless. This is my attempt:

from selenium import webdriver
from time import sleep
import undetected_chromedriver as uc
from selenium.webdriver.common.by import By
import threading
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


def main():
    driver.get('http://zefoy.com')
    sleep(10) #give time to solve captcha
    print('switching')
    opt.headless = True
    opt.add_argument('--headless')
    opt.add_argument('--disable-gpu')
    #begin automation


if __name__ == "__main__":
    opt = webdriver.ChromeOptions()
    driver = uc.Chrome(use_subprocess=True, options=opt)
    wait = WebDriverWait(driver, 15)
    driver.set_window_size(1024, 480)
    driver.delete_all_cookies()
    main()

But it doesn't work and the interface stays Thanks

xtekky
  • 572
  • 1
  • 4
  • 13
  • Does this answer your question? [Selenium / Python switch webdriver from headless to window mode](https://stackoverflow.com/questions/49134440/selenium-python-switch-webdriver-from-headless-to-window-mode) – nathan liang Mar 23 '22 at 23:58
  • 2
    Specifically, the comment by @sytech "Just start the driver as headed to begin with. There is no way to switch after the driver has been launched. Creating a new driver and copying the state may be possible, but depends on what the website uses to maintain the session (and if you need the session maintained at all). But the obvious solution is just to use a headed browser to start with." – nathan liang Mar 23 '22 at 23:59
  • 1
    I fixed it by making the user solve the captch and then generating a session id I then reuse when reloading the page in headless mode which "bypasses" the captcha – xtekky Mar 24 '22 at 01:29

0 Answers0