How to set selenium webdriver from headless mode to normal mode within the same session?

115
March 23, 2022, at 06:30 AM

Is it possible after setting selenium webdriver to a headless mode set it back to a normal mode?

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
driver.get(http://stackoverflow.com)
# set driver back to normal mode
Answer 1

No, it won't be possible to make Chrome operate initially in headless mode and then switch back to normal mode within the same session.

When you configure an instance of a ChromeDriver with ChromeOptions() to span a new Chrome Browsing Context the configuration gets baked within the chromedriver executable which will persist for the lifetime of the WebDriver and being uneditable. So you can't modify/add any existing/new configuration through ChromeOptions() class to the WebDriver instance which is currently in execution.

Even if you are able to extract the ChromeDriver and ChromeSession attributes e.g. Session ID, Cookies, UserAgent and other session attributes from the already initiated ChromeDriver and Chrome Browsing Session still you won't be able to change the set of attributes of the ChromeDriver.

A cleaner way would be to call driver.quit() within tearDown(){} method to close and destroy the current ChromeDriver and Chrome Browser instances gracefully and then span a new set of ChromeDriver and Chrome Browser instance with the new set of configurations.

tl; dr

You can find a couple of relevant discussions in:

  • Change ChromeOptions in an existing webdriver
  • How do I make Chrome Headless after I login manually
Rent Charter Buses Company
READ ALSO
Why is list count not working as I expect with nested lists?

Why is list count not working as I expect with nested lists?

I can count simple list but can not count list of lists

90
Iterate through Python for loop more quickly

Iterate through Python for loop more quickly

I have a Pandas data frame (called "ud_flex" below) that looks like the one below: The data frame has over 27 million observations in it that I'm trying to iterate through to do a calculation for each rowBelow is the calculation that I'm using:

122
how check python wrote package version automatically?

how check python wrote package version automatically?

How to check current running package and module version automatically based on something like hash, git(uncommitted is also required), change file date?

94
How to update Tweepy Streaming Python code

How to update Tweepy Streaming Python code

I had this code running for an earlier version of Python but now want to upgrade it to the latest version of Python and Tweepy however I cant seem to make it workAny help would be much appreciated! The error I get is:

174