Reputation: 133
I am using protractor to test, and I am trying to access an element on the HTML with a title tag. The problem is, when I try to append to the element with the title tag(I need a further down element to test the innerHTML), I get the "No element found using locator: By(css selector) error.
This code passes:
browser.element.all(by.css('div[data-row="1"]')).get(0).element(by.css('div[class="widget-body"]')).
element(by.css('section[class="scrollable"]')).element(by.css('div[title="myTitle: myTitle"]'));
But this code does not:
browser.element.all(by.css('div[data-row="1"]')).get(0).element(by.css('div[class="widget-body"]')).
element(by.css('section[class="scrollable"]')).element(by.css('div[title="myTitle: myTitle"]')).
element(by.css('span[class="text-I-Want ng-binding"]')).getInnerHtml();
Html element:
<div title="myTitle: myTitle">
<header><b class="ng-binding">myTitle</b></header>
<section>
<h3><span class="text-on-hand ng-binding">myTitle</span>
</section>
</div>
The data row/widget-body/scrollable elements are parent elements to the element I need to get to. I can't find any resources online that have told me why this happens. Can anyone help out?
Upvotes: 1
Views: 1402
Reputation: 473833
The reason the first block of code passes is that Protractor would not actually try to locate elements in this case at all. Only if you perform an action on an element, or ask for a certain property or attribute - then you would trigger Protractor to try locating the element.
In other words, the problem is in the way you locate the element.
The chain of locators you've built does not look reliable and you should debug which section of the chain is causing an error. Put a browser.pause()
or browser.debugger()
and try your CSS selectors in the shell.
It is difficult to tell more since there is no way for us to reproduce your problem.
Upvotes: 1