Unable to set window size in Headless Chrome (Selenium)

8,085 views
Skip to first unread message

no...@agentiq.com

unread,
Apr 27, 2018, 12:12:10 AM4/27/18
to robotframework-users
Hi all, I'm trying to run Headless Chrome so that I can run our Robot Selenium tests in Docker.  But the default window size is a little too small.  How do I fix this?  I'm running headless using this function:

Open Headless Chrome Browser
    [arguments]  ${page}
    ${chrome_options} =     Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
    Call Method    ${chrome_options}   add_argument    headless
    Call Method    ${chrome_options}   add_argument    disable-gpu
    ${options}=     Call Method     ${chrome_options}    to_capabilities
    Open Browser    ${page}    browser=chrome    remote_url=${REMOTESERVER}     desired_capabilities=${options}

This works just fine.  However, adding in 

"    Call Method    ${chrome_options}   add_argument    window-size=1920,1080"


Calling method 'add_argument' failed: TypeError: add_argument() got an unexpected keyword argument 'window-size'


If I then run it without the =1920,1080 at the end it runs and seems to recognize the error, then crashes.  So how does one set the window size to something appropriate?

Raghul Jayagopal

unread,
Apr 27, 2018, 12:14:35 AM4/27/18
to no...@agentiq.com, robotframework-users
Hi Noah,

Have u tried "Set Window Size” keyword.

Regards,
RJ

-- 
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at https://groups.google.com/group/robotframework-users.
For more options, visit https://groups.google.com/d/optout.

Raghul Jayagopal

unread,
Apr 27, 2018, 12:20:35 AM4/27/18
to no...@agentiq.com, robotframework-users
Alternate capability you use try "start-maximized

Regards,
RJ


On 27 Apr 2018, at 9:45 am, no...@agentiq.com wrote:

Mariusz Truszkowski

unread,
May 8, 2018, 9:05:00 AM5/8/18
to robotframework-users
Try this:

Call Method    ${chrome_options}    add_argument    window-size\=1920x1080

Barry

unread,
Oct 29, 2018, 4:39:26 PM10/29/18
to robotframework-users
None of those work for me.  The real problem is that Chrome Settings fails to recognize device pixel ratio on a Retina laptop, so my screen sticks at 1/2 size, which puts it into Responsive mode and I get a reduced interface.  Not fixed, but not Robot's fault, IMHO.

Douglas Rosa

unread,
Oct 30, 2018, 7:45:25 AM10/30/18
to barry....@gmail.com, robotframe...@googlegroups.com
I'ts works for me... try it...

Open Browser To Login Page
${chrome_options}= Evaluate
... sys.modules['selenium.webdriver'].ChromeOptions() sys
Call Method ${chrome_options} add_argument test-type
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 ${BROWSER} executable_path=${PATH} chrome_options=${chrome_options}
Set Window Size 1920 1080
Go To ${LOGIN_URL}

--

Barry

unread,
Oct 30, 2018, 9:27:34 AM10/30/18
to robotframework-users
Thanks, Douglas - the last line fixed it by setting it in the failing test: Set Window Size as Raghul Jayagopal mentioned above.  I was trying to set it from earlier documentation I had that Mariusz Truszkowski mentioned above:

Call Method    ${c_opts}   add_argument    window-size\=1920,1080

That doesn't work.    This does:  Set Window Size    1920    1080
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-users+unsub...@googlegroups.com.

Damodharan Baskaran

unread,
Nov 2, 2018, 2:29:43 AM11/2/18
to robotframework-users
You can set the window size as argument by this way.

${ws}=    Set Variable    window-size=1920,1080
Call Method    ${chrome options}    add_argument    ${ws}

Thanks,
Damodharan B
Reply all
Reply to author
Forward
0 new messages