Protractor - How to find an element within an element when the Protractor is also the main element elsewhere on the page

<div class="base-view app-loaded" data-ng-class="cssClass.appState">
<div class="ng-scope" data-ng-view="">
<div class="ng-scope" data-ng-include="'partial/navigation/navigation.tpl.html'">
<div class="feedback-ball feedback-ball-show feedback-ball-big" data-ng-class="feedback.cls" data-ng-click="outside($event)" data-feedback-ball="">
<span class="close-button"></span>
<h2 class="ng-binding">Welcome to Garbo</h2>
<div class="ng-scope ng-binding" data-ng-bind-html="feedback.html" data-ng-if="feedback.html">
<p>Here you can play in style in a safe and secure environment.</p>
<p>
<a class="btn" href="/account">My Account</a>
<a class="btn" href="/deposit">Deposit</a>
</p>
</div>
</div>
</div>

      

I want to find and click the / account button inside data-ng-bind-html = "feedback.html", I can find data-ng-bind-html = "feedback.html", but I couldn't find the account button inside it. when i try to find the account button, it gives me the error that the page has multiple account buttons, so be more specific.

I tried element. (). element () but it didn't work please help

+3


source to share


2 answers


element

calls can be chained
to find elements within other elements, so your solution element().element()

should work.

Alternatively, you can build an xpath expression to reach the link inside the appropriate one div

:



element(by.xpath('//div[@data-ng-bind-html = "feedback.html"]//a[@href = "/account"]'))

      

+4


source


The problem is that webDriver finds more than one element that matches. You have an element to find only one, and element.all to accept an array of elements, then you can use .get () and the index of the element, or first () or last (). You can do,

element(by.css('[data-ng-bind-html="feedback.html"]')
.element(by.cssContainingText('.btn', 'My account'));

      

If that doesn't work you may have more than one, if possible you can use



element(by.css('[data-ng-bind-html="feedback.html"]')
.all(by.cssContainingText('.btn', 'My account')).first();

      

But there you will have more than one button in your HTML, webDriver will only get one, Another thing is to use count (), which gives you the length of the array of elements, and you can know how many you have.

+3


source







All Articles