user10312643
user10312643

Reputation:

Change WebDriver from GUI to Headless

I want to automate an application for an upload process with selenium.Therefore I am using geckodriver. Right now I am doing the login site headless but I want to do the login by the user and then change to headless. Is there a way to do that or at least a work around?

Upvotes: 0

Views: 405

Answers (1)

Corey Goldberg
Corey Goldberg

Reputation: 60654

There is no way to do that using the same browser instance... The headless flag is a setting passed to the browser on startup and there is no way to dynamically change that.

If the site uses cookie-based authentication, here is an alternate approach:

  1. login with browser in normal (GUI) mode
  2. export saved cookies
  3. instantiate a new browser in headless mode
  4. navigate to the site again with the headless driver
  5. add saved cookies to the new headless driver

... at that point, you can navigate to an authenticated page. You should be "logged in" since you are re-using the cookies from the original browser session.

Upvotes: 2

Related Questions