How do I make Chrome Headless after I login manually

后端 未结 2 2059
我在风中等你
我在风中等你 2020-11-29 12:54

I am testing my site. I want the chrome browser to go headless after I manually enter the login credentials.

My selenium code to connect to the website.



        
2条回答
  •  悲&欢浪女
    2020-11-29 13:39

    No, it won't be possible to make Chrome operate headlessly after you login manually.

    When you configure an instance of a ChromeDriver using ChromeOptions() or DesiredCapabilities() in the process of initiating a new Chrome Browsing Session the configuration gets baked into the chromedriver executable and will persist till the lifetime of the WebDriver and being uneditable. So you can't add any further ChromeOptions 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:

    • How to set selenium webdriver from headless mode to normal mode within the same session?
    • Change ChromeOptions in an existing webdriver

提交回复
热议问题