WebDriver - sendKeys(input) does not complete before sendKeys(Keys.RETURN)

帅比萌擦擦* 提交于 2019-12-04 04:17:01

问题


My test is entering keys in an search text box, that's mostly ajax, and then pressing enter from the keyboard. There is no button to "start" the search so we're using the Enter key.

I'm using ChromeDriver as Firefox is not supported for our application with regards to this flow.

For my webdriver code (java), I'm having it do this:

searchIcon.click(); //opens the ajax overlay of the search text box
searchBox.clear(); //clears whatever text is already there
searchBox.sendKeys(input); //enters in the input text
searchBox.sendKeys(Keys.RETURN); //press return to start the search

The problem is, I noticed that the input text is not fully typed into the text box yet and the RETURN has already taken place. Basically, I'm doing a search of part of the input text that was entered.

Anyone encountering this? I tried to add an implicitwait before the Return action but since the elements are already loaded, that isn't going to help.


回答1:


Try this, once you enter the input into the search box, check whether the text is completely present or not inside the text box again using if statement, if complete text is present, then do the sendkeys(keys.return) part.

Just give it a try. Because once you entered the text into text box, in the next step the element obviously will be there.

Thank you, Shravan Kumar.T




回答2:


I also encountered same issue while executing my test. And it get resolved by updating webdriver to the latest version.

webdriver-manager update --versions.chrome=2.33
webdriver-manager start --versions.chrome=2.33


来源:https://stackoverflow.com/questions/24945082/webdriver-sendkeysinput-does-not-complete-before-sendkeyskeys-return

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!