How to use element.getLocation method in Appium

Best JavaScript code snippet using appium

rwd-asserter.js

Source:rwd-asserter.js Github

copy

Full Screen

...156 if (elements.length == 0) {157 return true;158 }159 else {160 let location = await element.getLocation();161 let size = await element.getSize();162 var e_endy = location.y + size.height;163 164 for (var i = 0; i < elements.length; i++) {165 let location = await elements[i].getLocation();166 var i_starty = location.y;167 // if the second element's start y comes before the first element's 168 // end y 169 if (i_starty < e_endy) {170 return false;171 }172 }173 }174 return true;175 }176 // Make sure that param element is below of each element in param elements177 this.assertElementBelowOf = async function (element, elements) {178 let result = await elementIsBelowOf(element, elements);179 expect(result).toBe(true);180 };181 async function elementIsBelowOf(element, elements) {182 if (elements.length == 0) {183 return true;184 }185 else {186 let location = await element.getLocation();187 var e_starty = location.y;188 for (var i = 0; i < elements.length; i++) {189 let location = await elements[i].getLocation();190 let size = await element.getSize();191 var i_endy = location.y + size.height;192 if (e_starty < i_endy) {193 return false;194 }195 }196 }197 return true;198 }199 // Make sure that param element is to the left of each element in param elements200 this.assertElementToLeftOf = async function (element, elements) {201 let result = await elementIsToLeftOf(element, elements);202 expect(result).toBe(true);203 };204 async function elementIsToLeftOf(element, elements) {205 if (elements.length == 0) {206 return true;207 }208 else {209 let location = await element.getLocation();210 let size = await element.getSize();211 var e_endx = location.x + size.width;212 for (var i = 0; i < elements.length; i++) {213 let location = await elements[i].getLocation();214 if (e_endx > location.x) {215 return false;216 }217 }218 }219 return true;220 }221 // Make sure that param element is to the right of each element in param elements222 this.assertElementToRightOf = async function (element, elements) {223 let result = await elementIsToRightOf(element, elements);224 expect(result).toBe(true);225 };226 async function elementIsToRightOf(element, elements) {227 if (elements.length == 0) {228 return true;229 }230 else {231 let location = await element.getLocation();232 var e_startx = location.x;233 for (var i = 0; i < elements.length; i++) {234 let location = await elements[i].getLocation();235 let size = await elements[i].getSize();236 var i_endx = location.x + size.width;237 console.log("\te_startx=" + e_startx + ", i_endx=" + i_endx);238 if (e_startx < i_endx) {239 return false;240 }241 }242 }243 return true;244 }245 // Make sure that param element is placed in the beginning of each element in param elements246 this.assertElementStartToStartOf = async function (element, elements) {247 let result = await elementStartToStartOf(element, elements);248 expect(result).toBe(true);249 };250 async function elementStartToStartOf(element, elements) {251 if (elements.length == 0) {252 return true;253 }254 else {255 let location = await element.getLocation();256 var e_startx = location.x;257 for (var i = 0; i < elements.length; i++) {258 let location = await elements[i].getLocation();259 var i_startx = location.x;260 // Note: Needs revision.. There is no room for error, e_startx is able to amount261 // to 91.9625015258789262 console.log("\te_startx=" + e_startx + ", i_startx=" + i_startx);263 if (e_startx !== i_startx) {264 return false;265 }266 }267 }268 return true;269 }270 // Make sure that param element ends at the end of each element in param elements271 this.assertElementEndToEndOf = async function (element, elements) {272 let result = await elementEndToEndOf(element, elements);273 expect(result).toBe(true);274 };275 async function elementEndToEndOf(element, elements) {276 if (elements.length == 0) {277 return true;278 }279 else {280 let location = await element.getLocation();281 let size = await element.getSize();282 var e_endx = location.x + size.width;283 for (var i = 0; i < elements.length; i++) {284 let location = await elements[i].getLocation();285 let size = await elements[i].getSize();286 var i_endx = location.x + size.width;287 // Note: Needs revision.. There is no room for error, e_endx is able to amount288 // to 657.9625015258789 and i_endx to 657.9750061035156289 // solution: add a margin of error of 1 px..290 console.log("\te_endx=" + e_endx + ", i_endx=" + i_endx);291 292 var diff = Math.abs(e_endx - i_endx);293 if (diff > 1) {294 return false;...

Full Screen

Full Screen

PopupForm.js

Source:PopupForm.js Github

copy

Full Screen

1Type.registerNamespace("AE");2AE.PopupForm = function(element) {3 AE.PopupForm.initializeBase(this, [element]);4 this._InputIds = [];5 this._ValidatorIds = [];6 this._inputs = {};7 this._validators = [];8 this._buttons = [];9 this._moveToCenter = false;10 this._moveToClick = false;11 this._animate = false;12 this._showVeil = false;13 this._veilCloses = false;14 this._veil = null;15 this._openTrigger = null;16 this._closeTrigger = null;17 this._errorPlaceholder = null;18}19AE.PopupForm.prototype = {20 initialize: function() {21 AE.PopupForm.callBaseMethod(this, 'initialize');22 this._handleClickDel = Function.createDelegate(this, this._handleClick);23 this._openDel = Function.createDelegate(this, this.Open);24 this._closeDel = Function.createDelegate(this, this.Close);25 this._callbackResultDel = Function.createDelegate(this, this._callbackResult);26 //this.GetElementByServerId = Function.createDelegate(this, this._getElementByServerId);27 this._window = $get(this.get_element().id + '_window');28 for (var i = 0; i < this._InputIds.length; i++) {29 this._inputs[this._InputIds[i].serverId] = $get(this._InputIds[i].clientId);30 }31 for (var i = 0; i < this._ValidatorIds.length; i++) {32 this._validators.push($get(this._ValidatorIds[i]));33 }34 for (var i = 0; i < this._buttons.length; i++) {35 var btn = $get(this._buttons[i].id);36 btn.button = this._buttons[i];37 $addHandler(btn, 'click', this._handleClickDel);38 }39 if (this._openTrigger)40 $addHandler(this._openTrigger, 'click', this._openDel);41 if (this._closeTrigger)42 $addHandler(this._closeTrigger, 'click', this._closeDel);43 //if (this._showVeil) {44 // this._initVeil();45 //}46 },47 get_inputs: function() {48 return this._InputIds;49 },50 set_inputs: function(value) {51 this._InputIds = value;52 },53 get_validators: function() {54 return this._ValidatorIds;55 },56 set_validators: function(value) {57 this._ValidatorIds = value;58 },59 get_input: function(id) {60 return this._inputs[id];61 },62 get_buttons: function() {63 return this._buttons;64 },65 set_buttons: function(value) {66 this._buttons = value;67 },68 get_moveToCenter: function() {69 return this._moveToCenter;70 },71 set_moveToCenter: function(value) {72 this._moveToCenter = value;73 },74 get_moveToClick: function() {75 return this._moveToClick;76 },77 set_moveToClick: function(value) {78 this._moveToClick = value;79 },80 get_animate: function() {81 return this._animate;82 },83 set_animate: function(value) {84 this._animate = value;85 },86 get_openTrigger: function() {87 return this._openTrigger;88 },89 set_openTrigger: function(value) {90 this._openTrigger = value;91 },92 get_closeTrigger: function() {93 return this._closeTrigger;94 },95 set_closeTrigger: function(value) {96 this._closeTrigger = value;97 },98 get_showVeil: function() {99 return this._showVeil;100 },101 set_showVeil: function(value) {102 this._showVeil = value;103 },104 get_veilCloses: function() {105 return this._veilCloses;106 },107 set_veilCloses: function(value) {108 this._veilCloses = value;109 },110 get_errorPlaceholder: function() {111 return this._errorPlaceholder;112 },113 set_errorPlaceholder: function(value) {114 this._errorPlaceholder = value;115 },116 IsValid: function() {117 var isValid = true;118 for (v in this._validators) {119 isValid &= v.validate();120 }121 return isValid;122 },123 GetData: function() {124 var data = {};125 for (i in this._inputs) {126 if (this._inputs[i] != null) {127 data[i] = getValue(this._inputs[i]);128 }129 }130 this.get_element().value = Sys.Serialization.JavaScriptSerializer.serialize(data);131 return this.get_element().value;132 },133 GetElementByServerId: function(id) {134 return $get(this.get_element().id + '_' + id);135 },136 _callbackResult: function(res, ctxt) {137 var cb;138 try {139 cb = Sys.Serialization.JavaScriptSerializer.deserialize(res);140 } catch (e) {141 cb = res;142 }143 if (typeof cb === 'object' && cb.errors) {144 this._errorPlaceholder.innerHTML = cb.errorMsg;145 }146 if (ctxt.button.button.clientCallback) {147 ctxt.button.button.clientCallback(cb, ctxt);148 }149 },150 Open: function(e) {151 if (e) e.preventDefault();152 this._onOpen();153 if (this._showVeil) {154 this._initVeil();155 this._veil.style.display = '';156 }157 if (this._moveToCenter) {158 this._doMoveToCenter();159 } else if (this._moveToClick && e) {160 this._doMoveToClick(e);161 }162 if (this._animate) {163 $(this._window).fadeIn('fast', this._reDoMove);164 } else {165 $(this._window).show();166 this._reDoMove();167 }168 },169 _reDoMove: function(e) {170 if (this._moveToCenter) {171 this._doMoveToCenter();172 } else if (this._moveToClick && e) {173 this._doMoveToClick(e);174 }175 },176 _onOpen: function() {177 var h = this.get_events().getHandler('open');178 if (h) h(this, Sys.EventArgs.Empty);179 },180 add_open: function(h) {181 this.get_events().addHandler(h);182 },183 Close: function() {184 this._onClose();185 if (this._veil) {186 this._veil.style.display = 'none';187 }188 if (this._animate) {189 $(this._window).fadeOut('fast', null);190 } else {191 $(this._window).hide();192 }193 },194 _onClose: function() {195 var h = this.get_events().getHandler('close');196 if (h) h(this, Sys.EventArgs.Empty);197 },198 add_close: function(h) {199 this.get_events().addHandler(h);200 },201 _handleClick: function(e) {202 e.preventDefault();203 if (e.target.button.onclick) {204 if (typeof e.target.button.onclick === 'function') {205 e.target.button.onclick(e);206 } else {207 eval(e.target.button.onclick);208 }209 }210 if (e.target.button.callback) {211 var ctxt = { 'control': this, 'button': e.target };212 var callbackArg = this._escape(e.target.button.serverId) + "|" + this._escape(this.GetData());213 var callbackResultDel = this._callbackResultDel;214 eval(e.target.button.callback);215 } else if (e.target.button.postback) {216 eval(e.target.button.postback);217 }218 return false;219 },220 _escape: function(str) {221 return str.replace("\\", "\\\\").replace("|", "\\|");222 },223 _initVeil: function() {224 var el = this.get_element();225 if (!el) return;226 var v = null;227 if (!this._veil) {228 v = document.createElement('div');229 v.style.backgroundColor = '#aaa';230 v.style.opacity = '.50';231 v.style.visibility = 'visible';232 v.style.filter = 'alpha(opacity=50)';233 v.style.position = 'absolute';234 v.style.display = 'none';235 v.style.zIndex = '4';236 this._veil = v;237 el.parentNode.appendChild(v);238 if (this._veilCloses) {239 $addHandler(this._veil, 'click', this._closeDel);240 }241 } else242 v = this._veil;243 var w, h;244 w = document.body.offsetWidth;245 if (window.innerHeight && window.scrollMaxY !== undefined) {246 h = window.innerHeight + window.scrollMaxY;247 }248 else if ((document.documentElement ? document.documentElement.scrollHeight : document.body.scrollHeight) > document.body.offsetHeight) // all but Explorer Mac249 {250 h = (document.documentElement ? document.documentElement.scrollHeight : document.body.scrollHeight);251 }252 else // works in Explorer 6 Strict, Mozilla (not FF) and Safari253 {254 h = document.body.offsetHeight + document.body.offsetTop;255 }256 h += 50;257 if (h < screen.availHeight) {258 h = screen.availHeight;259 }260 v.style.width = w + 'px';261 v.style.height = h + 'px';262 //var loc = Sys.UI.DomElement.getLocation(v);263 //var offX = loc.x;264 //var offY = loc.y;265 if (v.offsetParent && v.offsetParent.style.position == 'absolute') {266 var loc = Sys.UI.DomElement.getLocation(v.offsetParent);267 v.style.top = loc.y + 'px';268 v.style.left = loc.x + 'px';269 } else {270 v.style.top = '0px';271 v.style.left = '0px';272 }273 },274 _doMoveToCenter: function() {275 this._centered = true;276 var el = this._window;277 el.style.top = '';278 el.style.left = '';279 var w = this._getWinWidth();280 var h = this._getWinHeight();281 var loc = Sys.UI.DomElement.getLocation(el);282 var offX = loc.x;283 var offY = loc.y;284 offX = document.documentElement.scrollLeft > 0 ? document.documentElement.scrollLeft : document.body.scrollLeft;285 offY = document.documentElement.scrollTop > 0 ? document.documentElement.scrollTop : document.body.scrollTop;286 if (el.offsetParent) {287 var loc = Sys.UI.DomElement.getLocation(el.offsetParent);288 if (loc.x >= 0 && loc.y >= 0) {289 offX += offX - loc.x;290 offY += offY - loc.y;291 }292 }293 //var offX = 0;294 //var offY = 0;295 var elWidth = el.style.width ? parseInt(el.style.width) : null;296 var elHeight = el.style.height ? parseInt(el.style.height) : null;297 if (!elWidth || !elHeight) {298 var vis = el.style.visibility;299 var pos = el.style.position;300 var disp = el.style.display;301 el.style.visibility = 'hidden';302 el.style.position = 'absolute';303 el.style.display = 'inline';304 if (!elWidth) {305 elWidth = el.clientWidth;306 }307 if (!elHeight) {308 elHeight = el.clientHeight;309 }310 el.style.top = '0px';311 el.style.display = disp;312 el.style.position = pos;313 el.style.visibility = vis;314 }315 var lft = Math.round((w / 2) - (elWidth / 2) + offX);316 var top = Math.round((h / 2) - (elHeight / 2) + offY);317 if (lft < 0 || top < 0) {318 lft = 50;319 top = 50;320 }321 el.style.left = lft + 'px';322 el.style.top = top + 'px';323 },324 _doMoveToClick: function(e) {325 var el = this._window;326 //var offset = this.getDocumentOffset();327 var offset = el.offsetParent ? Sys.UI.DomElement.getLocation(el.offsetParent) : Sys.UI.DomElement.getLocation(el);328 var scrollX = document.documentElement != 'undefined' ? document.documentElement.scrollLeft : document.body.scrollLeft;329 var scrollY = document.documentElement != 'undefined' ? document.documentElement.scrollTop : document.body.scrollTop;330 var elWidth = el.style.width ? parseInt(el.style.width) : null;331 var elHeight = el.style.height ? parseInt(el.style.height) : null;332 if (!elWidth || !elHeight) {333 var vis = el.style.visibility;334 var pos = el.style.position;335 var disp = el.style.display;336 el.style.visibility = 'hidden';337 el.style.position = 'absolute';338 el.style.display = '';339 if (!elWidth) {340 elWidth = el.clientWidth;341 }342 if (!elHeight) {343 elHeight = el.clientHeight;344 }345 el.style.display = disp;346 el.style.position = pos;347 el.style.visibility = vis;348 }349 var cx = e.clientX;350 var cy = e.clientY;351 var winWidth = this._getWinWidth();352 var winHeight = this._getWinHeight();353 if (cx - elWidth / 2 - 25 < 0) {354 cx += Math.abs(cx - elWidth / 2 - 25);355 }356 if (cx + elWidth / 2 > winWidth - 25) {357 cx -= cx + elWidth / 2 - winWidth + 25;358 }359 if (cy - elHeight / 2 - 25 < 0) {360 cy += Math.abs(cy - elHeight / 2 - 25);361 }362 if (cy + elHeight / 2 > winHeight - 25) {363 cy -= cy + elHeight / 2 - winHeight + 25;364 }365 el.style.left = Math.round(cx - offset.x + (2 * scrollX) - elWidth / 2) + 'px';366 el.style.top = (cy - offset.y + (2 * scrollY) - elHeight / 2) + 'px';367 },368 _getWinWidth: function() {369 return window.innerWidth ? window.innerWidth : (document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth);370 },371 _getWinHeight: function() {372 return window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight);373 }374}375AE.PopupForm.registerClass('AE.PopupForm', Sys.UI.Control);...

Full Screen

Full Screen

Element.js

Source:Element.js Github

copy

Full Screen

...65 const element = await el;66 await element.waitForExist(this.timeout, `${elementName} does not exist`);67 68 const params = {69 'x': await element.getLocation('x'),70 'y': await element.getLocation('y')71 };72 this.deviceType === 'android'73 ? await driver.touchPerform([74 { action: 'tap', options: params },75 { action: 'release' }76 ])77 : await browser.execute('mobile: tap', params);78 79 await browser.pause(pause);80 };81 /**82 * Safe method for checking is element exist83 * @param {Element} el84 * @returns {Boolean}85 */86 async isExisting(el) {87 const element = await el;88 try {89 return await element.isExisting();90 } catch (e) {91 console.log(e.message);92 return false; 93 }94 }95 /**96 * Safe method for checking is element displayed97 * @param {Element} el98 * @returns {Boolean}99 */100 async isDisplayed(el) {101 const element = await el;102 try {103 return await element.isDisplayed();104 } catch (e) {105 console.log(e.message);106 return false; 107 }108 }109 110 /**111 * Get width position in percents112 * @param {Element} el113 */114 async getXLocation(el, elementName = 'Element') {115 const element = await el;116 await element.waitForExist(this.timeout, `${elementName} does not exist`);117 const deviceWidth = await this.screen.getWidth();118 const x = await element.getLocation('x');119 const elementWidth = await element.getSize('width');120 const xPosition = x + elementWidth / 2;121 return Math.round((xPosition / deviceWidth) * 100); 122 };123 /**124 * Get height position in percents125 * @param {Element} el126 */127 async getYLocation(el, elementName = 'Element') {128 const element = await el;129 await element.waitForExist(this.timeout, `${elementName} does not exist`);130 const deviceHeight = await this.screen.getHeight();131 const y = await element.getLocation('y');132 const elementHeight = await element.getSize('height');133 const yPosition = y + elementHeight / 2;134 return Math.round((yPosition / deviceHeight) * 100); 135 };136 _parseBounds(bounds) {137 const regex = /\d+/g;138 return bounds.match(regex).map(Number);139 };140}...

Full Screen

Full Screen

main.page.js

Source:main.page.js Github

copy

Full Screen

1class MainPage {23 get signUpForGitHubBtn(){4 return $('[class="btn-mktg btn-primary-mktg width-full width-sm-auto"]');5 }67 get signInForGitHubBtn(){8 return $('[class="HeaderMenu-link flex-shrink-0 no-underline"]');9 }1011 get mainProfileImgIcon(){12 return $('[class="Header-item position-relative mr-0 d-none d-md-flex"]');13 }1415 get yourProfileBtn(){16 return $('[href="/TestAccountQAAutomation"][class="dropdown-item"]');17 }1819 get whyGitHubBtn(){20 return $('//summary[contains(text(),"Why GitHub")]/..');21 }2223 get exploreBtn(){24 return $('//summary[contains(text(),"Explore")]/..');25 }2627 get pricingBtn(){28 return $('//summary[contains(text(),"Pricing")]/..');29 }3031 get plansBtn(){32 return $('details [href="/pricing"]');33 }3435 get exploreGitHubBtn(){36 return $('[href="/explore"]');37 }3839 get searchInput(){40 return $('[class*="form-control input-sm header-search-input jump-to-field js-jump-to-field js-site-search-focus"]');41 }4243 get searchBtn(){44 return $('[class="js-jump-to-badge-search-text-global d-none"]');45 }4647 get jumpToSearchResult(){48 return $('#jump-to-results');49 }5051 get enterpriseBtn(){52 return $('[href="/enterprise"][class*="HeaderMenu-link"]');53 }5455 get careersBtn(){56 return $('[href="/about/careers"]');57 }5859 async clickSignUpForGitHubBtn(){60 let signUpForGitHubBtnElement = await this.signUpForGitHubBtn;61 await signUpForGitHubBtnElement.click();62 }6364 async clickSignInForGitHubBtn(){65 let signInForGitHubBtnElement = await this.signInForGitHubBtn;66 await signInForGitHubBtnElement.click();67 }6869 async clickMainProfileImgIcon(){70 let mainProfileImgIconElement = await this.mainProfileImgIcon;71 await mainProfileImgIconElement.click();72 }7374 async clickYourProfileBtn(){75 let yourProfileBtnElement = await this.yourProfileBtn;76 await yourProfileBtnElement.click();77 }7879 async mouseOverWhyGitHubBtn(){80 let whyGitHubBtnElement = await this.whyGitHubBtn;81 let XOff = await whyGitHubBtnElement.getLocation('x');82 let YOff = await whyGitHubBtnElement.getLocation('y');83 await whyGitHubBtnElement.moveTo({XOff,YOff}); 84 }8586 async mouseOverExploreBtn(){87 let exploreBtnElement = await this.exploreBtn;88 let XOff = await exploreBtnElement.getLocation('x');89 let YOff = await exploreBtnElement.getLocation('y');90 await exploreBtnElement.moveTo({XOff,YOff}); 91 }9293 async mouseOverPricingBtn(){94 let pricingBtnElement = await this.pricingBtn;95 let XOff = await pricingBtnElement.getLocation('x');96 let YOff = await pricingBtnElement.getLocation('y');97 await pricingBtnElement.moveTo({XOff,YOff}); 98 }99100 async scrollUpExplore(){101 let exploreBtnElement = await this.exploreBtn;102 await exploreBtnElement.scrollIntoView();103 }104105 async clickPlansBtn(){106 let plansBtnElement = await this.plansBtn;107 await plansBtnElement.click();108 }109110 async clickExploreGitHubBtn(){111 let exploreGitHubBtnElement = await this.exploreGitHubBtn;112 await exploreGitHubBtnElement.click();113 }114115 async clickSearchInput(){116 let searchInputElementToClick = await this.searchInput;117 await searchInputElementToClick.click();118 }119120 async setSearchInput(){121 let sarchInputElement = await this.searchInput;122 await sarchInputElement.setValue('webdriverio');123 }124125 async clickSearchBtn(){126 let searchBtnElement = await this.searchBtn;127 await searchBtnElement.click();128 }129130 async clickJumpToSearchResult(){131 let jumpToSearchResultBtn = await this.jumpToSearchResult;132 await jumpToSearchResultBtn.click();133 }134135 async clickEnterpriseBtn(){136 let enterpriseBtnElement = await this.enterpriseBtn;137 await enterpriseBtnElement.click();138 }139140 async clickCareersBtn(){141 let careersBtnElement = await this.careersBtn;142 await careersBtnElement.click();143 }144}145 ...

Full Screen

Full Screen

basepage.page.js

Source:basepage.page.js Github

copy

Full Screen

...96 }97 waitForAnimation(element) {98 element.waitForDisplayed();99 browser.waitUntil(() => {100 const oldX = element.getLocation('x');101 const oldY = element.getLocation('y');102 browser.pause(200);103 const newX = element.getLocation('x');104 const newY = element.getLocation('y');105 return oldX === newX && oldY === newY;106 });107 }108}...

Full Screen

Full Screen

85207.user.js

Source:85207.user.js Github

copy

Full Screen

1// ==UserScript==2// @id rsm_intranet_net-compatibility3// @name [ Intranet ] .Net Compatibility4// @namespace dev.rsalazar.name5// @author rsalazar6// @description Fixes some .Net incompatibilities with Firefox 4 beta4+7// @include https://my-intranet/8// ==/UserScript==910(function( ) {11 /**12 * .Net-related - object document::getBoxObjectFor( string )13 * Dropped in Mozilla 1.9.2 (Firefox 3.6) - added support for getBoundingClientRect()14 */15 var box = function( id ) {16 var resl, el = document.getElementById(id);17 if ( !el ) return null;18 resl = el.getBoundingClientRect();19 resl.parentOffset = null;20 resl.element = el;21 resl.screenX = window.screenX + resl.left;22 resl.screenY = window.screenY + resl.top;23 resl.x = resl.left;24 resl.y = resl.top;25 return resl;26 }; // [object] document::getBoxObjectFor( string )272829 /**30 * .Net-related - object Sys::UI::DomElement::getLocation( HtmlElement )31 * Fixes "I.document is undefined" exception32 */33 var loc = false;34 if ( 'https:' == document.location.protocol && 'undefined' != typeof unsafeWindow.Sys35 && 'undefined' != typeof unsafeWindow.Sys.UI.DomElement ) {36 loc = function( I ) {37 if ( I.self || I.nodeType == 9 ) {38 return new Sys.UI.Point( 0, 0 );39 }40 try {41 var H = I.getBoundingClientRect(); // Added in Mozilla 1.9.2 (Firefox 3.6)42 } catch ( F ) {43 return new Sys.UI.Point( 0, 0 );44 }45 if ( !H ) {46 return new Sys.UI.Point( 0, 0 );47 }4849 var G = (I.document || I.ownerDocument).documentElement,50 E = H.left - 2 + G.scrollLeft,51 D = H.top - 2 + G.scrollTop;52 try {53 var B = I.ownerDocument.parentWindow.frameElement || null;54 if ( B ) {55 var C = 2 - (B.frameBorder || 1) * 2;56 E += C;57 D += C;58 }59 } catch ( A ) {60 } // try..catch61 return new Sys.UI.Point( E, D );62 }; // Sys::UI::Point Sys::UI::DomElement::getLocation( HtmlElement )63 }646566 /**67 * Finally, add the functions to the page68 */69 var script = document.createElement('script');70 script.type = 'application/javascript';71 script.innerHTML = 'if ( \'function\' != typeof document.getBoxObjectFor )\n'72 +'document.getBoxObjectFor = ('+ box.toString() +')'73 +( !loc ? '' : ';\nSys.UI.DomElement.getLocation = ('+ loc.toString() +');' );74 document.head.appendChild(script); ...

Full Screen

Full Screen

DOMElementPatch.js

Source:DOMElementPatch.js Github

copy

Full Screen

1/**2 * Electsys++ Project3 * ----------------------------4 * Sys.UI.DomElement 补丁5 * 修复了页面滚动后滑条失效的问题6 */7function patch_fix_dom_element() {8 jQuery(document).ready(function () {9 // Apply patch into original scripts10 jQuery('body').append(`11 <script>12 console.log(Sys.UI.DomElement.getLocation);13 if (Sys.UI.DomElement) {14 Sys.UI.DomElement.getLocation = function DomElement$getLocation(element) {15 /// <summary locid="M:J#Sys.UI.DomElement.getLocation">Gets the coordinates of a DOM element.</summary>16 /// <param name="element" domElement="true"></param>17 /// <returns type="Sys.UI.Point">A Point object with two fields, x and y, which contain the pixel coordinates of the element.</returns>18 var e = Function._validateParams(arguments, [{19 name: "element",20 domElement: true21 }]);22 if (e)23 throw e;24 if (element.self ||25 element.nodeType === 9 ||26 (element === document.documentElement) ||27 (element.parentNode === element.ownerDocument.documentElement)) {28 return new Sys.UI.Point(0,0);29 }30 var clientRect = element.getBoundingClientRect();31 if (!clientRect) {32 return new Sys.UI.Point(0,0);33 }34 // 原脚本此处可能得到浮点值的 offsetX 和 offsetY,导致后续脚本出错,此处已修正35 var ex, ownerDoc = element.ownerDocument,36 documentElement = ownerDoc.documentElement,37 offsetX = Math.round(clientRect.left + (documentElement.scrollLeft || (ownerDoc.body ? ownerDoc.body.scrollLeft : 0))),38 offsetY = Math.round(clientRect.top + (documentElement.scrollTop || (ownerDoc.body ? ownerDoc.body.scrollTop : 0)));39 return new Sys.UI.Point(offsetX,offsetY);40 }41 }42 </script>43 `);44 });...

Full Screen

Full Screen

ActionsTest.js

Source:ActionsTest.js Github

copy

Full Screen

1let expect = require('chai').expect;2describe.only("actions", () => {3 before(function() {4 browser.url("/dnd.html");5 });6 // * Only works on FF for now7 // * Requires a web page with drag and drop elements8 it('should execute a sequence of mouse actions', function () {9 let dragElementLocation = $(".drag-element").getLocation();10 let dropElementLocation = $(".drop-element").getLocation();11 browser.performActions([{12 "type": "pointer",13 "id": "drag-n-drop",14 "parameters": {"pointerType": "mouse"},15 "actions": [16 {"type": "pointerMove", "duration": 0, "x": dragElementLocation.x+10, "y": dragElementLocation.y+10},17 {"type": "pointerDown", "button": 0},18 {"type": "pause", "duration": 500},19 {"type": "pointerMove", "duration": 1000, "origin": "pointer", "x": dropElementLocation.x+10, "y": dropElementLocation.y+10},20 {"type": "pointerUp", "button": 0}21 ]22 }]);23 // Release actions24 browser.releaseActions();25 expect($(".drop-element").getText()).to.equal("Dropped");26 let dragElementNewLocation = $(".drag-element").getLocation();27 expect(dragElementNewLocation.x).to.be.gt(dragElementLocation.x);28 expect(dragElementNewLocation.y).to.be.gt(dragElementLocation.y);29 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver'),2 until = webdriver.until;3var driver = new webdriver.Builder()4 .forBrowser('chrome')5 .build();6driver.manage().window().maximize();7driver.findElement(By.name('q')).sendKeys('webdriver');8driver.findElement(By.name('btnG')).click();9driver.wait(until.titleIs('webdriver - Google Search'), 1000);10driver.findElement(By.name('q')).getLocation().then(function(loc) {11 console.log(loc);12});13driver.quit();14{ x: 16, y: 80 }

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.iphone()).build();3driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');4driver.findElement(webdriver.By.name('btnG')).click();5driver.wait(function() {6 return driver.getTitle().then(function(title) {7 return title === 'webdriver - Google Search';8 });9}, 1000);10driver.findElement(webdriver.By.name('btnG')).getLocation().then(function(loc) {11 console.log(loc);12});13driver.quit();14{ x: 0, y: 0 }15var webdriver = require('selenium-webdriver');16var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.iphone()).build();17driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');18driver.findElement(webdriver.By.name('btnG')).click();19driver.wait(function() {20 return driver.getTitle().then(function(title) {21 return title === 'webdriver - Google Search';22 });23}, 1000);24driver.findElement(webdriver.By.name('btnG')).getLocationInView().then(function(loc) {25 console.log(loc);26});27driver.quit();28{ x: 16, y: 16 }

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require("assert");3var serverConfig = {4};5var driver = wd.promiseChainRemote(serverConfig);6var desired = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var Q = require('q');4var desired = {5};6var driver = wd.promiseChainRemote("localhost", 4723);7 .init(desired)8 .elementByName('q')9 .getLocation()10 .then(function (location) {11 console.log("location of element is: " + JSON.stringify(location));12 assert.ok(location.x > 0);13 assert.ok(location.y > 0);14 })15 .fin(function () { return driver.quit(); })16 .done();17location of element is: {"x":0,"y":0}

Full Screen

Using AI Code Generation

copy

Full Screen

1var element = driver.findElement(webdriver.By.id('com.android.calculator2:id/digit_2'));2element.getLocation().then(function(location) {3 driver.tap(1, location.x, location.y, 1000);4});5var element = driver.findElement(webdriver.By.id('com.android.calculator2:id/digit_2'));6element.getSize().then(function(size) {7 driver.tap(1, size.width, size.height, 1000);8});9var element = driver.findElement(webdriver.By.id('com.android.calculator2:id/digit_2'));10element.getAttribute('value').then(function(value) {11 driver.tap(1, value, value, 1000);12});13var element = driver.findElement(webdriver.By.id('com.android.calculator2:id/digit_2'));14element.getText().then(function(text) {15 driver.tap(1, text, text, 1000);16});17var element = driver.findElement(webdriver.By.id('com.android.calculator2:id/digit_2'));18element.isDisplayed().then(function(isDisplayed) {19 if(isDisplayed){20 driver.tap(1, element, element, 1000);21 }22});23var element = driver.findElement(webdriver.By.id('com.android.calculator2:id/digit_2'));24element.isEnabled().then(function(isEnabled) {25 if(isEnabled){26 driver.tap(1,

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful