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)