4

Hu guys,

I have a problem when I want to click on a link that is in list on html page. Here is my html:

<h3>{{snapshot.contractKey}}&nbsp;</h3>
    <ul class="nav nav-pills nav-stacked">
                <li><a id="documentLink" href="" ng-click="checkAndRedirect('/document1/')"><span translate="contractDetail.document1"> Document</span>&nbsp;<i class="fa fa-file-text"></i></a></li>
                <li class="active"><a id="detailsLink" href="" ng-click="checkAndRedirect('/document2/')"> <span translate="contractDetail.document2"> Details</span>&nbsp;<i class="fa fa-list-ul"></i></a></li>
                <li><a id="revisionsLink" href="" ng-click="checkAndRedirect('/document3/')"> <span translate="contractDetail.document3"> Revisions </span>&nbsp;<i class="fa fa-exchange"></i></a></li>
                <li><a id="auditTrailLink" href="" ng-click="checkAndRedirect('/document4/')"> <span translate="contractDetail.document4"> Audit Trail</span>&nbsp;<i class="fa fa-tasks"></i></a></li>
                <li><a id="actionHistoryLink" href="" ng-click="checkAndRedirect('/document5/')"> <span translate="contractDetail.document5">Action History </span>&nbsp;<i class="fa fa-clock-o"></i></a></li>
     </ul>

When I want to click on a link by its ID in protractor test, error is shown No such element or Element is not visible.

Here is my test line of code:

element(by.id('documentLink')).click();

Do you know why it is bad solution and what do to?

When I do this:

element.all(by.tagName('a')).then(function(results){ 
        expect(results.length).toEqual(5);
  });

he returns me that is correct and there are 5 links on page. But when I try to access them by ID, I can not do that?

Dejan Jankovic
  • 173
  • 4
  • 11

1 Answers1

6

From your comment, I suggest you to use the onPrepare option in your Protractor config to maximize the browser window before your specs start running:

onPrepare: function() {
  browser.driver.manage().window().maximize();
}
glepretre
  • 8,154
  • 5
  • 43
  • 57
  • I have one more question: if I have integration with one other site that is established when I click on button, can I proceed to test some workflow scenario and on that other site, using ids of elements that I get by firebug for example? Is that a problem, because that is however different site? – Dejan Jankovic May 22 '14 at 09:58
  • Wow that can be another good question to ask on SO! What do you mean by 'integration'? Is it included in your page, is it a different route, a popup? You should open a new question and give more details about your case ;) – glepretre May 22 '14 at 10:06
  • Yeah, I will do so, and link question to you here :) – Dejan Jankovic May 22 '14 at 10:07
  • This is link to another question :) http://stackoverflow.com/questions/23805527/is-protractor-testing-possible-when-i-have-integration-with-other-site – Dejan Jankovic May 22 '14 at 11:28
  • This doesn't work for me, one has to scroll to get to the element I'm interacting with in my case :( It doesn't fit on the screen even when maximized. – axk Jul 07 '14 at 18:02
  • 1
    @axk So you need to "tell" Protractor to scroll down. Maybe these answers can help you : http://stackoverflow.com/a/23573893 or http://stackoverflow.com/a/24181048 ;) – glepretre Jul 08 '14 at 06:37