1
votes

Running a simple end to test using protractor, load a page, click on a button and the navigate to the next page after clicking the button but i'm getting the following error No element found using locator: by.buttonText(Register as a Buyer) This is the HTML behind the button

<a href="/register/buyer" class="btn" data-ss1491391037="1">
                    Register as a Buyer</a>

And snippet from my protractor file

element(by.buttonText("Register as a Buyer")).click();

Not sure what I'm missing here or what I'm supposed to change, I'm brand new to Protractor. I was able to get something similar above to work using a different button, except that button had a value assigned to it in the HTML code whereas the above doesn't.

Thanks for any help

2
Please put some wait and try element(by.xpath("//a[contains(text(), 'Register as a Buyer')]")).click(); - Kishan Patel
Thanks a million, that works - Edmond
The above worked for me but it may be helpful for other people who are new to Protractor to post an answer - Edmond
Means? I am not getting you - Kishan Patel
That's a link, not a button. So you can't use buttonText... - Gunderson

2 Answers

2
votes

Like buttons, protractor also has special methods to identify anchor tags based on their text. Try using by.linkText() or by.partialLinkText()

1
votes

The element you're trying to click is not a button, but rather a link. Thus, by.buttonText won't work... you can use one of the following:

element(by.cssContainingText('.btn', 'Register as a Buyer')).click();

or if you only have one .btn link:

$('.btn').click();

or perhaps you have many buttons but want to click the first one:

$$('.btn').first().click();