SELENIUM2 Learning -030-webui Automation Practical instance -028-get the element position and size

Source: Internet
Author: User
Tags gety

During automated testing, it is sometimes necessary to get the position and size of the element, to get the position of the element, to simulate the mouse with the actions, and to perform relative coordinates. For example, some elements are not easy to locate, or you need to take a brute-force click test of an element's relative area range, you need to get the coordinates.

Get the element location and size of the source code is relatively simple, directly on the code ... Please see!

1     /**2 * Get element position, and return integer Array [left, top, width, height]3      * 4      * @authorAARON.FFP5      * @versionV1.0.0:autoseleniumdemo main.aaron.sele.core Seleniumcore.java getelementpositionandsize, 2015-7-27 23:38:31 Exp $6      * 7      * @paramWebdriver:webdriver8      * @paramBy:by9      * Ten      * @returnInt[left,top,width,height] One      */ A      Public int[] getelementpositionandsize (Webdriver webdriver, by) { -         //Store Element Position -         int[] Elementposition =New int[4]; the          -         //get Element -webelement element =webdriver.findelement (by); -          +         //get location of element -Point e_location =element.getlocation (); +          A         //get size of element atDimension e_size =element.getsize (); -          -Elementposition[0] =e_location.getx (); -ELEMENTPOSITION[1] =e_location.gety (); -ELEMENTPOSITION[2] =E_size.width; -ELEMENTPOSITION[3] =E_size.height; in          -         returnelementposition; to     } +      -     /** the * Get element position, and return integer Array [left, top, width, height] *      *  $      * @authorAARON.FFPPanax Notoginseng      * @versionV1.0.0:autoseleniumdemo main.aaron.sele.core Seleniumcore.java getelementpositionandsize, 2015-7-27 23:35:31 Exp $ -      *  the      * @paramBy:by +      *  A      * @returnInt[left,top,width,height] the      */ +      Public int[] Getelementpositionandsize (by) { -         //Store Element Position $         int[] Elementposition =New int[4]; $          -         //get Element -webelement element = This. webdriver.findelement (by); the          -         //get location of elementWuyiPoint e_location =element.getlocation (); the          -         //get size of element WuDimension e_size =element.getsize (); -          AboutElementposition[0] =e_location.getx (); $ELEMENTPOSITION[1] =e_location.gety (); -ELEMENTPOSITION[2] =E_size.width; -ELEMENTPOSITION[3] =E_size.height; -          A         returnelementposition; +}

At this point, theWebUI automation function test Script No. 028-Get the element location and size of the smooth end, I hope this article can give beginners Selenium you a reference.

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 -030-webui Automation Practical instance -028-get the element position and 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.