Search code examples
seleniumselenium-webdriverselenium-chromedriverrobotframeworkgoogle-chrome-headless

How to maximize Headless Chrome window in Robot Framework?


I'm not able to start Headless chrome with a maximized window. I tried two solutions but none of them worked for me. First solution :

Open Browser    ${LOGIN_URL}    headlesschrome
Maximize Browser Window

Second one :

${chrome_options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
Call Method    ${chrome_options}    add_argument    --start-maximized
Create Webdriver    Chrome    chrome_options=${chrome_options}
Go To   ${LOGIN_URL}
Maximize Browser Window

what's the thing i'm doing wrong in my solutions ?


Solution

  • The solution was to use Set Window Size :

    Call Method    ${chrome_options}    add_argument    --disable-extensions
    Call Method    ${chrome_options}    add_argument    --headless
    Call Method    ${chrome_options}    add_argument    --disable-gpu
    Call Method    ${chrome_options}    add_argument    --no-sandbox
    Create Webdriver    Chrome    chrome_options=${chrome_options}
    Set Window Size ${1400} ${600}
    Go To   ${LOGIN_URL}