Problem with Chromedriver in Headless mode
I have noticed that in my case and worked perfectly.You need add window size as an arguments in headless Mode.I don't know which language you are working on.
If you are using python
add this .
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('window-size=1920x1080')
if you are using java
add this.
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("headless");
chromeOptions.addArguments("window-size=1920,1080");
Please try this and let me know if this work.
Kanchan Ruia
Updated on June 25, 2022Comments
-
Kanchan Ruia about 2 years
I would like to know if anyone there has ever had a problem using the chromedriver in "headless" mode. In my case, when running selenium tests in this mode, the execution of the same is stopped indefinitely, not completing the test and starts execution of the next test case nor does it give the relevant exception. I would like to know if anyone can have any idea of what may be occurring. I am guessing this issue is due to static initialization of the webdriver
public static WebDriver createInstance(WebDriver driver, String browserName){..}
My logs show me this sequence the test cases are not completely executed and next test case is called
- INFO learning.helpers.DriverInitialisor - createInstance - 111 - Running Chrome browser in headless mode - INFO learning.helpers.DriverInitialisor - createInstance - 126 - Launching Chrome browser in local mode - INFO learning.tests.ExpandFAQ - expandAndCollapseFAQ - 30 - launching the ION Learning Hub Application - INFO learning.tests.ExpandFAQ - expandAndCollapseFAQ - 35 - Open a searched product - INFO learning.helpers.DriverInitialisor - createInstance - 111 - Running Chrome browser in headless mode - INFO learning.helpers.DriverInitialisor - createInstance - 126 - Launching Chrome browser in local mode - INFO learning.tests.CollapseFAQ - collapseFAQ - 30 - launching the ION Learning Hub Application - INFO learning.tests.CollapseFAQ - collapseFAQ - 35 - Open a searched product
This continues for few test cases and then complete execution starts again for other test cases. I am running of around 50 test cases. There is no multithreading implemented.
-
Kanchan Ruia over 5 yearsHi @Kajal Kundu I am using Java. I have already used above mentioned code options.addArguments("headless") options.addArguments("window-size=1366x768"); options.addArguments("--incognito");
-
KunduK over 5 years@KanchanRuia :
options.addArguments("window-size=1366,768");
-
KunduK over 5 yearsIf is not working you need to increase your window-size dimension.
-
Priya about 3 years@KunduK Thank you. Your solution worked for me. I am using python and I had the same issue. Just a very slight edit (I am sure it was a typo) : Semi colon at the end needs to be removed in python solution
-
KunduK about 3 years@Priya : Thanks. I have updated the same.