2

I keep getting Failed: invalid element state error on attempt to sendKeys() to a text box to which I'm able to if I'm in browser.explore() mode.

the Text field is validating entry against active userIDs. Please note that I'm able to use the same command sendKeys() when I'm in browser.explore() mode

UPDATE: I'm not able to post HTML code as there is a char. limit and I have over 7500 arrays [object Object] here is a screenshot, if it helps screenshot of the field and its HTML

my code:

var businessOwner = element(by.name("productManager"));
businessOwner.sendKeys('someValue');

error:- Failed: invalid element state (Session info: chrome=62.0.3202.94) (Driver info: chromedriver=2.34.522932 (4140ab217e1ca1bec0c4b4d1b148f3361eb3a03e),platform=Mac OS X 10.12.6 x86_64) (Session info: chrome=62.0.3202.94) (Driver info: chromedriver=2.34.522932 (4140ab217e1ca1bec0c4b4d1b148f3361eb3a03e),platform=Mac OS X 10.12.6 x86_64) at WebDriverError (...pathToMyApp/node_modules/selenium-webdriver/lib/error.js:27:5) at InvalidElementStateError (...pathToMyApp/node_modules/selenium-webdriver/lib/error.js:100:5) at Object.checkLegacyResponse (...pathToMyApp/node_modules/selenium-webdriver/lib/error.js:505:15) at parseHttpResponse (...pathToMyApp/node_modules/selenium-webdriver/lib/http.js:509:13) at doSend.then.response (...pathToMyApp/node_modules/selenium-webdriver/lib/http.js:440:13) at process._tickCallback (internal/process/next_tick.js:103:7) From: Task: WebElement.sendKeys() at Driver.schedule (...pathToMyApp/node_modules/selenium-webdriver/lib/webdriver.js:816:17) at WebElement.schedule_ (...pathToMyApp/node_modules/selenium-webdriver/lib/webdriver.js:1921:25) at WebElement.sendKeys (...pathToMyApp/node_modules/selenium-webdriver/lib/webdriver.js:2084:19) at actionFn (...pathToMyApp/node_modules/protractor/lib/element.ts:94:34) at Array.map (native) at actionResults.getWebElements.then (...pathToMyApp/node_modules/protractor/lib/element.ts:484:67) at ManagedPromise.invokeCallback_ (...pathToMyApp/node_modules/selenium-webdriver/lib/promise.js:1366:14) at TaskQueue.execute_ (...pathToMyApp/node_modules/selenium-webdriver/lib/promise.js:2970:14) at TaskQueue.executeNext_ (...pathToMyApp/node_modules/selenium-webdriver/lib/promise.js:2953:27) at asyncRun (...pathToMyApp/node_modules/selenium-webdriver/lib/promise.js:2813:27) at ...pathToMyApp/node_modules/selenium-webdriver/lib/promise.js:676:7 at process._tickCallback (internal/process/next_tick.js:103:7)Error at ElementArrayFinder.applyAction_ (...pathToMyApp/node_modules/protractor/lib/element.ts:482:23) at ElementArrayFinder.(anonymous function) [as sendKeys] (...pathToMyApp/node_modules/protractor/lib/element.ts:96:21) at ElementFinder.(anonymous function) [as sendKeys] (...pathToMyApp/node_modules/protractor/lib/element.ts:873:14) at ...pathToMyApp/e2e/app.e2e-spec.ts:204:17 at elementArrayFinder_.then (...pathToMyApp/node_modules/protractor/lib/element.ts:840:22) at ManagedPromise.invokeCallback_ (...pathToMyApp/node_modules/selenium-webdriver/lib/promise.js:1366:14) at TaskQueue.execute_ (...pathToMyApp/node_modules/selenium-webdriver/lib/promise.js:2970:14) at TaskQueue.executeNext_ (...pathToMyApp/node_modules/selenium-webdriver/lib/promise.js:2953:27) at asyncRun (...pathToMyApp/node_modules/selenium-webdriver/lib/promise.js:2813:27) at ...pathToMyApp/node_modules/selenium-webdriver/lib/promise.js:676:7 at process._tickCallback (internal/process/next_tick.js:103:7) From: Task: Run it("I fill teamsAndOwners Form") in control flow at UserContext. (...pathToMyApp/node_modules/jasminewd2/index.js:94:19) at ...pathToMyApp/node_modules/jasminewd2/index.js:64:48 at ControlFlow.emit (...pathToMyApp/node_modules/selenium-webdriver/lib/events.js:62:21) at ControlFlow.shutdown_ (...pathToMyApp/node_modules/selenium-webdriver/lib/promise.js:2565:10) at shutdownTask_.MicroTask (...pathToMyApp/node_modules/selenium-webdriver/lib/promise.js:2490:53) at MicroTask.asyncRun (...pathToMyApp/node_modules/selenium-webdriver/lib/promise.js:2619:9) at ...pathToMyApp/node_modules/selenium-webdriver/lib/promise.js:676:7 at process._tickCallback (internal/process/next_tick.js:103:7) From asynchronous test: Error at Suite. (...pathToMyApp/e2e/app.e2e-spec.ts:170:1) at Object. (...pathToMyApp/e2e/app.e2e-spec.ts:7:1) at Module._compile (module.js:570:32) at Module.m._compile (...pathToMyApp/node_modules/ts-node/src/index.ts:382:23) at Module._extensions..js (module.js:579:10) at Object.require.extensions.(anonymous function) [as .ts] (...pathToMyApp/node_modules/ts-node/src/index.ts:385:12) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.require (module.js:497:17) at require (internal/module.js:20:19)

I've tried:

1.

browser.wait(EC.visibilityOf(businessOwner.get(0)), 30000, 'businessOwner is not there ');
businessOwner.sendKeys(UID);

same error no matter what the timeout is

2.

function setBusinessOwner(UID: string){
    browser.wait(EC.visibilityOf(businessOwner), 20000).then(function(){
        businessOwner.click().then(function(){
            businessOwner.sendKeys(UID);
});
});
}
setBusinessOwner('someValue');

same error.

***UPDATE(9am): seem like its timing issue (most likely)

adding browser.sleep(10000) allows my script to sendKeys without error.

why browser.wait(EC.visibilityOf(businessOwner) does not work then ... ? *** UPDATE(1020am) browser.wait(EC.elementToBeClickable(businessOwner) seem to be working. testing and if works, will resolve this issue

toxicBurn
  • 127
  • 11
  • please let me know what information is needed to troubleshoot this. thank you in advance – toxicBurn Dec 07 '17 at 23:54
  • i only know sendKeys as method of a WebDriver and not of a HTMLElement. How it works with the WebDriver you can find here: https://stackoverflow.com/questions/31632923/using-javascriptexecutor-to-sendkeys-plus-click-on-web-element – mtizziani Dec 08 '17 at 08:35
  • at which location you are getting this error. It will help me to investigate if you share complete log. – Yash Jagdale Dec 10 '17 at 05:23
  • @mtizziani, sorry if I'm not clear: I'm not able to post the HTML of the element to show how it looks – toxicBurn Dec 11 '17 at 16:55
  • @YashJagdale, i've updated the issue with a log – toxicBurn Dec 11 '17 at 17:25

1 Answers1

2

Here is the code that finally works

function setBusinessOwner(UID: string){
  browser.wait(EC.elementToBeClickable(businessOwner), 20000).then(function(){
      businessOwner.sendKeys(UID);
});
}
setBusinessOwner('abc1234');

elementToBeClickable - seem to be working. I don't know what is the implementation difference between elementToBeClickable and visibilityOf, but visibilityOf was not working out for me

toxicBurn
  • 127
  • 11
  • visibilityOf is wait till element is visible, It will return true once element available in dom. elementToBeClickable - Wait untill that element is not clickable.(it will return false if any button is visible but not clickable.) - Hope this help you – Yash Jagdale Jan 19 '18 at 05:44