Ramtin Soltani
Ramtin Soltani

Reputation: 2700

Protractor sendKeys doesn't send anything to the textbox

I have the following code which tends to enter a verification code inside a single input form.

The form is part of the signup process of an angular app that will check the verification code to be the same as the one written on the mySQL table.

There's a previous form before the verification which has multiple inputs (First name, Last name, phone, and password) with a next button which proceeds to the verification process.

All the web elements are successfully located, the signup function is using q to do everything in order using promises.

Here's the code:

.then(function() {
  return signupModalButton.click(); // The next button on the first form
})

.then(function() {
  return common.waitForElementToBeVisible(signupModalCode); // Wait for the code input to be visible
})

.then(function() {
  return getVerificationCodeFromDatabase(phoneUsed); // Read the code from mySQL database
})

.then(function(code) {

  console.log('Got verification code: ' + code); // Logs correctly
  signupModalCode.sendKeys(code); // No keys get sent to the text box event if I change this to:
  //signupModalCode.sendKeys('test');

  browser.wait(function() {
    var ec = protractor.ExpectedConditions;
    return ec.textToBePresentInElement(signupModalCode);
  }, config.WAITING_TIMEOUT); // Same output with or without this browser.wait

  signupModalCode.getText().then(function(text) {
    console.log('text inside element: ' + text);
  }) // Nothing gets logged

  console.log('Entered code...'); // Gets logged!
  return signupModalButton.click(); // Doesn't happen
})

.then(function() { // Code doesn't reach here
  console.log('Promise resolved...'); // Doesn't get logged
})

When the test is running I can see the text box but I see that no text gets typed in there, then the browser gets closed and the following error will appear in the console:

C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:108
  var template = new Error(this.message);
                 ^
UnknownError: Session ID is null. Using WebDriver after calling quit()?
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 03:03:16'
System info: host: 'Morbid-PC', ip: '169.254.67.136', os.name: 'Windows 8.1', os.arch: 'amd64', os.version: '6.3', java.version: '1.7.0_72'
Driver info: driver.version: EventFiringWebDriver
    at new bot.Error (C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:108:18)
    at Object.bot.response.checkResponse (C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\response.js:109:9)
    at C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:379:20
    at [object Object].promise.ControlFlow.runInFrame_ (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1857:20)
    at [object Object].goog.defineClass.notify (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2448:25)
    at [object Object].promise.Promise.notify_ (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:564:12)
    at Array.forEach (native)
    at [object Object].promise.Promise.notifyAll_ (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:553:15)
    at goog.async.run.processWorkQueue (C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:130:15)
    at runMicrotasksCallback (node.js:337:7)
Error
    at [object Object].ElementArrayFinder.applyAction_ (C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\lib\element.js:392:21)
    at [object Object].self.(anonymous function) [as sendKeys] (C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\lib\element.js:76:19)
    at [object Object].self.(anonymous function) [as sendKeys] (C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\lib\element.js:721:11)
    at C:\Users\ramtin\trooptraining\troop\troop-web\test\protractor\assets\lib-auth.js:224:23
    at [object Object].promise.ControlFlow.runInFrame_ (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1857:20)
    at [object Object].goog.defineClass.notify (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2448:25)
    at [object Object].promise.Promise.notify_ (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:564:12)
    at Array.forEach (native)
    at [object Object].promise.Promise.notifyAll_ (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:553:15)
    at goog.async.run.processWorkQueue (C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:130:15)
From: Task: WebDriver.quit()
    at [object Object].webdriver.WebDriver.schedule (C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:362:15)
    at [object Object].webdriver.WebDriver.quit (C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:445:21)
    at C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\lib\driverProviders\driverProvider.js:59:14
    at [object Object].promise.ControlFlow.runInFrame_ (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:1857:20)
    at [object Object].goog.defineClass.notify (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:2448:25)
    at [object Object].promise.Promise.notify_ (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:564:12)
    at Array.forEach (native)
    at [object Object].promise.Promise.notifyAll_ (C:/Users/ramtin/AppData/Roaming/npm/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:553:15)
    at goog.async.run.processWorkQueue (C:\Users\ramtin\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:130:15)
    at runMicrotasksCallback (node.js:337:7)
[launcher] Process exited with error code 1

I can't figure out what's the problem with accessing this one text box, and how protractor skips the ones related to that text box.

Any help would be appreciated.

Upvotes: 3

Views: 762

Answers (1)

alecxe
alecxe

Reputation: 473843

I think you have to either nest the callbacks:

.then(function() {
  return signupModalButton.click().then(function() {
    return common.waitForElementToBeVisible(signupModalCode).then(function() {
      return getVerificationCodeFromDatabase(phoneUsed).then(function(code) {
        // etc...
      });
    });
  });
});

Or, don't explicitly resolve the promises at all and let the Control Flow handle it.

Upvotes: 3

Related Questions