SELENIUM2 Learning -022-webui Automation Practical Instance -020-javascript application example in Selenium automation (get browser display area size)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.