I am using Selenium Remote Control . During executing the tests the actual Firefox window is so small. I want it full screen so I can see what is happening. How can I maximize the browser screen?
Try the windowMaximize command:
selenium.windowMaximize();
You can also set a specific width and height using the following command:
selenium.getEval("window.resizeTo(X, Y); window.moveTo(0,0);")
Where X is the width and Y is the height.
This works for me. All the other solutions didn't work in FF7.
WebDriver driver = ((WebDriverBackedSelenium) selenium).getWrappedDriver();
driver.manage().window().setPosition(new Point(0, 0));
driver.manage().window().setSize(new Dimension(1920, 1080));
You can do the following:
page.driver.browser.manage.window.maximize
Selenium 2.31.0
driver = webdriver.Firefox()
# Resize the window to the screen width/height
driver.set_window_size(300, 500)
# Move the window to position x/y
driver.set_window_position(200, 200)
for Firefox: sel.key_press_native(122) (122 in the key code for F11)
Well I think the best way is to use selenium.windowMaximize() selenium function instead of manipulating the windows size.
None of the answers provided work when passing the -singlewindow parameter to the Selenium RC server. However, if you pass a firefox profile to the Selenium RC server (as detailed somewhat here), you can make an empty profile folder and put this file in the folder:
localstore.rdf(case sensitive filename!):
<?xml version="1.0"?>
<RDF:RDF xmlns:NC="http://home.netscape.com/NC-rdf#"
xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<RDF:Description RDF:about="chrome://browser/content/browser.xul#main-window"
sizemode="normal"
height="9999"
width="9999"
screenX="0"
screenY="0" />
lastSelected="paneTabs" />
<RDF:Description RDF:about="chrome://browser/content/browser.xul">
<NC:persist RDF:resource="chrome://browser/content/browser.xul#main-window"/>
<NC:persist RDF:resource="chrome://browser/content/browser.xul#PersonalToolbar"/>
<NC:persist RDF:resource="chrome://browser/content/browser.xul#nav-bar"/>
<NC:persist RDF:resource="chrome://browser/content/browser.xul#status-bar"/>
<NC:persist RDF:resource="chrome://browser/content/browser.xul#toggle_taskbar"/>
<NC:persist RDF:resource="chrome://browser/content/browser.xul#navigator-toolbox"/>
<NC:persist RDF:resource="chrome://browser/content/browser.xul#toolbar-menubar"/>
<NC:persist RDF:resource="chrome://browser/content/browser.xul#sidebar-box"/>
<NC:persist RDF:resource="chrome://browser/content/browser.xul#sidebar-title"/>
</RDF:Description>
</RDF:RDF>
Replace width and height with your preferred width and height. 9999x9999 will pretty much maximize any monitor.
The simplest example possible of running your Selenium RC server this way assuming we have the previously mentioned localstore.rdf in our home directory, and we are currently in the directory of the Selenium RC server:
rm -rf ~/ffProfile
mkdir ~/ffProfile
cp localstore.rdf ~/ffProfile
java -jar selenium-server-*.jar -singlewindow -firefoxProfileTemplate "~/ffProfile"
This also has the added benefit of not "polluting" your tests.
To expand on David Hunt's suggestion for more specific window resizing and moving note the following.
To work in most environments move before resizing. That is:
selenium.getEval("window.moveTo(X, Y); window.resizeTo(X, Y); ")
To cover 2/3's of the screen, which is handy for seeing part of the selenium driving window underneath, and to do this regardless of your target screen resolution:
selenium.getEval("window.moveTo(screen.availWidth / 3,0); window.resizeTo(screen.availWidth * (2/3), screen.availHeight); ");
In ruby, the call would be
web_driver.manage.window.maximize
来源:https://stackoverflow.com/questions/1522252/how-to-resize-maximize-firefox-window-during-launching-selenium-remote-control