im using java selenium with chrome. I know to start headless mode but i want to pass to headless mode after some process. For instance, i got url and i clicked some buttons on visible normal webpage with selenium, then i want to hide that page with headless mode or anyother things. Is this possible?
-
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 30 '22 at 20:45
-
That is not possible. Once the session is created with desired properties, you cannot change them. – Nandan A May 31 '22 at 12:20
-
Thank you very much. I thought so, too. I thought there is a solution maybe but there isn't. Thanks... – Mehmet Ergul Jun 02 '22 at 06:06
1 Answers
Once the session is created you can't
When you configure an instance of a ChromeDriver using ChromeOptions(), 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 is 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.
You can find a couple of relevant discussions in: How can I switch from headless mode to normal mode using Google Chrome and Selenium??

- 68
- 6