SELENIUM2 Learning -031-webui Automation Practical Instance -029-javascript application example in Selenium automation (get element position and size)

Source: Internet
Author: User

Through JS or JQuery to get to the element, through Offsetleft, OffsetTop, offsetwidth, offsetheight can get the position and size of elements, very simple, directly on the source, please see!

1     /**2 * Get element position by jquery, and return an integer Array [left distance, top distance, width distance, height D Istance]3      * 4      * @authorAARON.FFP5      * @versionV1.0.0:autoseleniumdemo main.aaron.sele.core Seleniumcore.java getelementpositionandsizebyjquery, 2015-7-27 15:54:38 EXP $6      * 7      * @paramSelector:selector8      * 9      * @returnInt[left,top,width,height]Ten      */ One      Public int[] getelementpositionandsizebyjquery (String selector) { A         //Store Element Position -         int[] Elementposition =New int[4]; -          theString JQ = "Webelement = $ ('" + selector + "') [0];" + -"Return webelement.offsetleft + '; ' + webelement.offsettop + '; ' +" + -"Webelement.offsetwidth + '; ' + webelement.offsetheight"; -          +String[] Position = ((Javascriptexecutor) This. Webdriver). Executescript (JQ). ToString (). Split (";"); -          +Elementposition[0] = integer.valueof (position[0]); AELEMENTPOSITION[1] = integer.valueof (position[1]); atELEMENTPOSITION[2] = integer.valueof (position[2]); -ELEMENTPOSITION[3] = integer.valueof (position[3]); -          -         returnelementposition; -}

at this point, WebUI Automated functional test Scripts section 029-javascript Example of application in Selenium automation (get element position and size) Smooth completion, I hope this article can give beginners Selenium you a reference. (Application of Ps:jquery in Selenium I also categorized JavaScript, please know! )

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 -031-webui Automation Practical Instance -029-javascript application example in Selenium automation (get 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.