selenium - Testing relative positions of elements -


on page under test have following support link: enter image description here

which represented following html:

<div class="ap-version-panel ap-version-support">     <a href="http://site/support.html" target="_blank" ng-keydown="apversionctrl.keydownhandler($event)"><i class="fa fa-external-link"></i>support</a> </div> 

what i'm trying test icon located before "support" text. how can that?


i've tried following - locate icon element xpath additionally checks there "support" text after , check if element present:

expect(element(by.xpath("//text()[. = 'support']/preceding-sibling::i[contains(@class, 'fa-external-link')]")).ispresent().tobe(true); 

this works quite ugly , don't actual position check hidden inside xpath expression not readable , reliable. need more explicit.

i recommend changing product under test adding <span> , move text "support" <span>.

<div class="ap-version-panel ap-version-support">     <a href="http://site/support.html" target="_blank" ng-keydown="apversionctrl.keydownhandler($event)"><i class="fa fa-external-link"></i><span>support<span></a> </div> 

but if cannot change product, can use javascriptexecutor childnodes check order of nodes:

var afunctiontocheckorder = function (arguments) {     var nodes = arguments[0].childnodes;     var result;     // check nodes[0] = <i>     // check node [1] textnode , value = "support"     return result; } var supportlink = element(by.linktext("support")); browser.executescript(afunctiontocheckorder, supportlink).then(...) 

as can see, more uglier solution. you'd better change product under test.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -