<HTML><Head> <title>Position</title> <style>. Test{background:URL ("image/omeoclickimg.jpg"); } </style> <Scriptlanguage= "JavaScript"type= "Text/javascript"> functionC () {varObjtop=getoffsettop (document.getElementById ("D"));//object x Position varObjleft=Getoffsetleft (document.getElementById ("D"));//Object y position varMouseX=Event.clientx+Document.body.scrollLeft;//Mouse x position varMousey=Event.clienty+Document.body.scrollTop;//Mouse y position//calculate the relative position of a click varOBJX=MouseX-Objleft; varobjy=Mousey-Objtop; Clickobjposition=OBJX+ "," +objy; alert (clickobjposition); } functiongetoffsettop (obj) {vartmp=Obj.offsettop; varVal=obj.offsetparent; while(Val!= NULL) {tmp+=Val.offsettop; Val=val.offsetparent; } returntmp; } functionGetoffsetleft (obj) {vartmp=Obj.offsetleft; varVal=obj.offsetparent; while(Val!= NULL) {tmp+=Val.offsetleft; Val=val.offsetparent; } returntmp; } </Script></Head><Bodystyle= "margin:0px;"><Divstyle= "padding:90px;border:1px solid #ccc; font-size:36px;width:800px;height:800px;"></Div><DivID= "area"></Div><Divstyle= "width:1400px;height:300px;border:1px solid red;padding-left:1200px;"> <DivID= "D"class= "Test"style= "width:230px;height:230px;border:1px solid green;padding:10px;cursor:hand;"onclick= "C ()"></Div></Div></Body></HTML>
Selenium_ getting relative coordinates