Pindakaas
Pindakaas

Reputation: 4439

how to click a button for an protractor e2e test?

I am trying to write an e2e test with protractor and click this button:

<button class="btn btn-warning" ng-click="clickThis()">Here</button>

My test looks like this:

 element(by.buttonText('Here')).click();

When I run protractor I get an error:

 Failed: Timed out waiting for Protractor to synchronize with the page after 11 seconds.

How can I solve this?

Upvotes: 2

Views: 10995

Answers (2)

Avinash
Avinash

Reputation: 186

Instead of button text(which can be changed) use the xpath using the class. This should work

element(by.xpath('//button[@class="btn btn-warning"]')).click();

if you still have synchronisation issues, set browser.ignoreSynchronization = true;

Upvotes: 1

svassr
svassr

Reputation: 5668

Protractor consider visible text make sure your text is visible when the page loads.

If your modal takes time to appear that could be the reason. In that case make protractor wait for the modal to appear or use by.binding if you can.

Also make sure there is no CSS text-transform property applied to this text that could make it differ from "Here".

Upvotes: 0

Related Questions