0

Hello so i have been trying alot but i think it's impossible i need to run chrome driver using python selenium with headless on but at some point i want to turn off headless mode (in the middle of debugging for example) so i can solve the captcha or do something .. is it possible ?


from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
import chromedriver_autoinstaller


link = "https://www.google.com/recaptcha/api2/demo"
WINDOW_SIZE = "1920,1080"


try :  
        chromedriver_autoinstaller.install()
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument("--incognito")
        chrome_options.add_argument("--log-level=3")
        chrome_options.add_argument("--headless")
        chrome_options.add_argument("--window-size=%s" % WINDOW_SIZE)
        driver = webdriver.Chrome(chrome_options=chrome_options)
        wait = WebDriverWait(driver, 10)
        driver.maximize_window()


        driver.get(link)
        #i want to turn off headless here so i can solve the captcha for example 
        print("Cpathca Solved")
        #Then turn it back on again here
except :
    pass        
Prophet
  • 32,350
  • 22
  • 54
  • 79
lol saso
  • 11
  • 3
  • You can but you need to create a new driver when you switch. This will be a new browser session too. Procedure is close the current driver, create new driver...etc... you might also consider using HTMLUnit instead of headless chrome. (same procedure would apply...) – pcalkins Sep 12 '22 at 18:31
  • oh k thank yo i will try that but the problem is i can't close the current browser i want to solve the captcha manually that's all i will check HTMLUnit tho – lol saso Sep 12 '22 at 18:35
  • yea thank you @MichaelMintz i didn't see that – lol saso Sep 12 '22 at 18:37
  • 1
    If you're trying to avoid the captcha (and it's thrown because a site has detected selenium) then there are other answers on stack overflow that mention a python tool called ``undetected-chromedriver`` for that situation. – Michael Mintz Sep 12 '22 at 18:43

1 Answers1

1

No, you can't.
webdriver object is created with specified (or default) parameters that can't be changed during the session.

Prophet
  • 32,350
  • 22
  • 54
  • 79