Ziwdigforbugs
Ziwdigforbugs

Reputation: 1214

How to locate the element '54' with protractor and not with xpath

I am struggling to locate the number 54 (or the whole intern div) in the following HTML snippet, I don' want to sue xpath as my page structure change depending on search results. Please how can I locate it maybe using CSS? PS : I am using protractor to test an angular application.

<div class="listItem">
<div>
    <label class="ng-binding">54</label> <span class=
    "listItemNum ng-binding">1054</span>
</div>
</div> 

Upvotes: 0

Views: 1171

Answers (1)

Sirk
Sirk

Reputation: 1597

you could assign a unique ID in the html, though I think some people frown on that. heres a few links that might help you

// http://www.youtube.com/watch?v=idb6hOxlyb8 - a video someone made going through his protractor e2e test for his angular site

http://www.yearofmoo.com/2013/09/advanced-testing-and-debugging-in-angularjs.html - very good site with some good little tips n tricks with a video

https://docs.google.com/presentation/d/1QWFnYAur19R7RQ5KkLkLDMOMz5jrzNlBId3XBrwRNs8/edit#slide=id.gf9a5a479_019 - slides from the first video

the slides are probably your best bet as slide 11 onwards talks about protractor locators and css is one of them

here's what i would do for your little extract though its probably not going to be useful as the app gets bigger

var labelText = ptor.findElement(protractor.By.tagName('label').getText();
console.log(labelText);

that should print 54 to the console

hope this helps

Upvotes: 0

Related Questions