Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make headless browser visible Python

I have created a headless webdriver chrome browser by setting this argument:

chrome_options.add_argument("--headless")

and then opening the browser using:

driver = webdriver.Chrome(executable_path=os.path.abspath("chromedriver"), chrome_options=chrome_options)

Is it possible to make the browser appear once a condition is met? I have tried removing the attribute again using:

chrome_options.arguments.remove("--headless")

but that does not do anything.

like image 311
K Kreid Avatar asked Sep 16 '25 07:09

K Kreid


2 Answers

when you pass the --headless parameter to chrome it is actually creating the instance as headless, not creating a window and hiding it, if you wanted to show the instance when a condition is meet you must consider not using --headless at the chrome params.

like image 96
Shailyn Ortiz Avatar answered Sep 19 '25 08:09

Shailyn Ortiz


You are not going to be able to remove options/arguments from your Selenium sessions after the session has been started. Each Selenium session is created using a unique session ID and runs with the parameters passed to it until asked to .quit(). You will not be able to watch your Chrome session run if you pass it the --headless option when you start it.

like image 38
Nicholas Martinez Avatar answered Sep 19 '25 08:09

Nicholas Martinez