How to switch from headless chrome to headed chrome when a condition is met?

Viewed 869

Is it possible to switch from a headless chrome to a headed chrome when a certain condition is met/ or when something is called?

Here is my code:

import os  
from selenium import webdriver  
from selenium.webdriver.common.keys import Keys  
from selenium.webdriver.chrome.options import Options

chrome_options = Options()  
chrome_options.add_argument("--headless")  
chrome_options.binary_location = """/Applications/Google Chrome   
Canary.app/Contents/MacOS/Google Chrome Canary"""

driver = webdriver.Chrome(executable_path=os.path.abspath(“chromedriver")) 
chrome_options=chrome_options  
driver.get("http://www.google.com")

I have tried to remove options, but that does not seem to be working... I'm trying to switch from the headless form to the headed form when a certain element shows up...

if "google" in driver.page_source:
    "SWITCH TO HEADED BROWSER HERE AND DISPLAY THE SITE"

I know I could always just close instance and open up a new instance, but I was wondering if there was a way to do it like this, so the browser is essentially hidden until a condition is met.

0 Answers
Related