How do we get the size of the browser display area by briefly outlining how to get and set the browser window size in the previous articles? This article provides a brief overview of this, please refer to the small master. If there are deficiencies, please the great god, thank you!
To get the browser display area method, I now think of only the following two ways:
1. Get the size of the browser display area via JavaScript
2, by Webdriver, get the size, so that the size of the browser display area
This article mainly in the first Method example demonstration, the second method for subsequent updates, please look forward to! Thank you!
1 /**2 * Get width and height about display screens area by JavaScript3 * 4 * @authorAARON.FFP5 * @versionV1.0.0:autoseleniumdemo main.aaron.sele.core Seleniumcore.java getbrowserdisplayareasizebyjs, 2015-7-28 02:27:33 EXP $6 * 7 * @returnInt[width,height]8 */9 Public int[] Getbrowserdisplayareasizebyjs () {Ten int[] Browserdisplayareasize =New int[2]; OneString js = "return window.innerwidth + '; ' + window.innerheight"; A -String[] Areasize = ((Javascriptexecutor) This. Webdriver). Executescript (JS). toString (). Split (";"); - theBrowserdisplayareasize[0] = integer.valueof (areasize[0]); -BROWSERDISPLAYAREASIZE[1] = integer.valueof (areasize[1]); - - returnbrowserdisplayareasize; +}
From the browser's console, execute the script as shown in the results.
PS: In the actual use process, if the browser window size changes, you need to regain the size of the browser display area.
At this point, theWebUI automation function test script section 020-javascript in the Selenium Automation application instance of the second (get browser display area size) successfully completed, I hope this article can give beginners Selenium A reference for you.
Finally, very grateful to the pro-stop, I hope this article can be pro helpful. Warmly welcome the kiss to discuss together and progress together. Thank you so much! ^_^
SELENIUM2 Learning -022-webui Automation Practical Instance -020-javascript application example in Selenium automation (get browser display area size)