失败:尝试.sendKeys()到文本字段

时间:2017-12-07 23:38:25

标签: javascript typescript protractor

如果我Failed: invalid element state模式下我尝试sendKeys()browser.explore()一个文本框,我就会收到sendKeys()错误。

Text字段正在验证针对活动用户ID的条目。请注意,当我处于browser.explore()模式时,我可以使用相同的命令var businessOwner = element(by.name("productManager")); businessOwner.sendKeys('someValue');

更新:由于存在字符,我无法发布HTML代码。限制,我有超过7500个数组[对象对象] 这是截图,如果它有帮助 screenshot of the field and its HTML

我的代码:

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

错误: - 失败:元素状态无效          (会话信息:chrome = 62.0.3202.94)          (驱动程序信息:chromedriver = 2.34.522932(4140ab217e1ca1bec0c4b4d1b148f3361eb3a03e),platform = Mac OS X 10.12.6 x86_64)          (会话信息:chrome = 62.0.3202.94)          (驱动程序信息:chromedriver = 2.34.522932(4140ab217e1ca1bec0c4b4d1b148f3361eb3a03e),platform = Mac OS X 10.12.6 x86_64)            在WebDriverError(... pathToMyApp / node_modules / selenium-webdriver / lib / error.js:27:5)            在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)        来自:任务:WebElement.sendKeys()            在Driver.schedule(... pathToMyApp / node_modules / selenium-webdriver / lib / webdriver.js:816:17)            在WebElement.schedule_(... pathToMyApp / node_modules / selenium-webdriver / lib / webdriver.js:1921:25)            在WebElement.sendKeys(... pathToMyApp / node_modules / selenium-webdriver / lib / webdriver.js:2084:19)            at actionFn(... pathToMyApp / node_modules / protractor / lib / element.ts:94:34)            在Array.map(本机)            at actionResults.getWebElements.then(... pathToMyApp / node_modules / protractor / lib / element.ts:484:67)            在ManagedPromise.invokeCallback_(... pathToMyApp / node_modules / selenium-webdriver / lib / promise.js:1366:14)            在TaskQueue.execute_(... pathToMyApp / node_modules / selenium-webdriver / lib / promise.js:2970:14)            在TaskQueue.executeNext_(... pathToMyApp / node_modules / selenium-webdriver / lib / promise.js:2953:27)            at asyncRun(... pathToMyApp / node_modules / selenium-webdriver / lib / promise.js:2813:27)            在... pathToMyApp / node_modules / selenium-webdriver / lib / promise.js:676:7            at process._tickCallback(internal / process / next_tick.js:103:7)错误            在ElementArrayFinder.applyAction_(... pathToMyApp / node_modules / protractor / lib / element.ts:482:23)            在ElementArrayFinder。(匿名函数)[as sendKeys](... pathToMyApp / node_modules / protractor / lib / element.ts:96:21)            在ElementFinder。(匿名函数)[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)            在ManagedPromise.invokeCallback_(... pathToMyApp / node_modules / selenium-webdriver / lib / promise.js:1366:14)            在TaskQueue.execute_(... pathToMyApp / node_modules / selenium-webdriver / lib / promise.js:2970:14)            在TaskQueue.executeNext_(... pathToMyApp / node_modules / selenium-webdriver / lib / promise.js:2953:27)            at asyncRun(... pathToMyApp / node_modules / selenium-webdriver / lib / promise.js:2813:27)            在... pathToMyApp / node_modules / selenium-webdriver / lib / promise.js:676:7            at process._tickCallback(internal / process / next_tick.js:103:7)        来自:任务:在控制流程中运行它("我填写团队和所有者表格")            在UserContext。 (... pathToMyApp / node_modules / jasminewd2 / index.js:94:19)            at ... pathToMyApp / node_modules / jasminewd2 / index.js:64:48            在ControlFlow.emit(... pathToMyApp / node_modules / selenium-webdriver / lib / events.js:62:21)            在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)            在MicroTask.asyncRun(... pathToMyApp / node_modules / selenium-webdriver / lib / promise.js:2619:9)            在... pathToMyApp / node_modules / selenium-webdriver / lib / promise.js:676:7            at process._tickCallback(internal / process / next_tick.js:103:7)        从异步测试:        错误            在套房。 (... pathToMyApp / E2E / app.e2e-spec.ts:170:1)            在对象。 (... pathToMyApp / E2E / app.e2e-spec.ts:7:1)            在Module._compile(module.js:570:32)            在Module.m._compile(... pathToMyApp / node_modules / ts-node / src / index.ts:382:23)            在Module._extensions..js(module.js:579:10)            at Object.require.extensions。(匿名函数)[as .ts](... pathToMyApp / node_modules / ts-node / src / index.ts:385:12)            在Module.load(module.js:487:32)            在tryModuleLoad(module.js:446:12)            在Function.Module._load(module.js:438:3)            在Module.require(module.js:497:17)            at require(internal / module.js:20:19)

我尝试过:

1

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

同样的错误,无论超时是什么

2

{{1}}

同样的错误。

*** UPDATE(上午09点): 看起来像是时间问题(最有可能)

添加browser.sleep(10000)允许我的脚本无错误地发送。

为什么browser.wait(EC.visibilityOf(businessOwner)不起作用...? ***更新(上午10点20分) browser.wait(EC.elementToBeClickable(businessOwner)似乎正在运行。测试如果有效,将解决此问题

1 个答案:

答案 0 :(得分:0)

这是最终有效的代码

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

elementToBeClickable - 似乎正在运作。我不知道elementToBeClickable和visibilityOf之间的实现区别是什么,但是visibilityOf对我来说不起作用