Martin Milan
Martin Milan

Reputation: 6390

Protractor - clicking and sendKeys not working

I am writing a Protractor test, and as part of the test I wish to clear the content of a particular field (on a textarea), and then use the sendKeys method to write some content onto that textarea.

Here's the code from my test:

var commentField = element(by.css('input[ng-model="comment"]'));
console.log(commentField);
commentField.clear();
commentField.sendKeys('Here is a comment'); 

The console log confirms that I am indeed finding a control, but as soon as it hits the clear() method the test just hangs.

Any ideas what might be happening here?

Upvotes: 4

Views: 8103

Answers (3)

DarthOpto
DarthOpto

Reputation: 1652

There was(is) a problem with .clear() where if you didn't fulfill the promise, the sendKeys() method wouldn't work.

Try using async/await or fulfill the promise.

element.clear().then(() => {
    element.sendKeys('text to send')
})

Upvotes: 0

ktom
ktom

Reputation: 228

We use browser.ignoreSynchronization = true; if the page is not angular page. Because the protractor is coded for angular. But, I see ng selector:

var commentField = element(by.css('input[ng-model="comment"]'));

This error may be due to other things:

  1. Browser driver (Try to use chromedriver)
  2. Lack of testability plugin. Please visit this link for more information: https://www.npmjs.com/package/protractor-testability-plugin

Make sure you use jasmine2 framework, and to update webdriver, type to command line this: webdriver-manager update

Upvotes: 4

Martin Milan
Martin Milan

Reputation: 6390

Just to let people know - I needed to use

browser.ignoreSynchronization = true;

after the call to move to the target page, but before attempting to click, clear or edit anything.

Happy days!

Upvotes: 3

Related Questions