'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 1:[1]
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}
Solution 2:[2]
To maximize the Browsing Window while using google-chrome-headless you need to replace:
add_argument --start-maximized
With:
add_argument window-size=1400,600
Alternative
The command Maximize Browser Window
may still not be working in robotframework.
This is a known issue with robotframework for quite some time now. We have discussed this issue within the discussion "Maximise browser Window" keyword not working in IE,FF and chrome.I am using selenium2Library at length. However there is a work around provided by @srib4ufrnd
as follows:
- Step 1: When selenium2library is installed in robot frame work , the selenium2library will create the python files (these python files contains the python code for selenium keywords) in the path
C:\Python27\Lib\site-packages\Selenium2Library\keywords
- Step 2: Among these python files the code for keyword
Maximise browser window
is present in the python file with namebrowsermanagement.py
Step3: The code for Maximise browser window is not working.
def maximize_browser_window(self): """Maximizes current browser window.""" self._current_browser().execute_script("if (window.screen) { window.moveTo(0, 0); window.resizeTo(window.screen.availWidth, window.screen.availHeight); }")
Step 4: Copy the above file and save it with another name for backup sake. This will help us if we need to revert back quickly incase of any issues.
Step 5: Now replace the above mentioned code in the "_browsermanagement.py" file with the following code.
def maximize_browser_window(self): """Maximizes current browser window.""" self._current_browser().maximize_window()
- Step 6: Save the file
_browsermanagement.py
after editing.
Note: Ensure you are saving the file in proper encoding technique using only "notepad" which comes as deafult with windows to edit and save the file.
- Step 7: Execute your test which can now perform the same operation of the keyword Maximise browser window.
Reference
You can find a couple of relevant discussions in:
Solution 3:[3]
what worked for me
Call Method ${chrome options} add_argument window-size\=1400,600
notice the \=
because without it does not work
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Abdo Rabah |
Solution 2 | |
Solution 3 | JimS |