0

I am trying to press ENTER using nightwatch using below code in my test

module.exports = {
'Enter Text'(client) {
  client
  .url(url)
  .waitForElementVisible('element', 1000)
  .setValue('input[id="new-todo"]', ['abcdefgh', client.Keys.ENTER])
  .pause(10000)
  .end();

it opens chrome browser, sets the value but does not press ENTER. My application needs this to be done as pressing enter is the only option.

Below is the HTML code for the part I am trying to automate

 <header id="header">
<h1>todos</h1>
<input id="new-todo" disabled placeholder="What needs to be done?" autofocus data-weave="troopjs-todos/widget/create">
</header>
  • What does the HTML look like? Without it, we cannot be of much help here. I suspect though that you need to add a click command or a send keys with the enter. – QualiT Jan 10 '19 at 19:32
  • @QualiT I have added the HTML. Can you plz check – vivek.sahni Jan 11 '19 at 12:41

1 Answers1

0

I am assuming that there is some listener on that input field so that when it loses focus it saves. Assuming that, try this:

EDIT: The problem may be that that array in .setValue is not handled correctly. Try this:

module.exports = {
'Enter Text'(client) {
  client
  .url(url)
  .waitForElementVisible('element', 1000)
  .setValue('input[id="12345"]', 'abcdefgh')
  .keys(client.Keys.ENTER)
  .pause(10000)
  .end();
}
QualiT
  • 1,934
  • 2
  • 18
  • 37
  • Tried this. Doesn't work. There is a small script at the end of the page. Does that make a difference ? document.getElementById("new-todo").disabled=false; – vivek.sahni Jan 11 '19 at 17:04
  • A couple of questions: is your input a search field? Presumably it return a dynamic list of guesses at what you are searching for. In that case, I presume you'd know which response you want to click. Do you want to randomly go to a specific result, similar to Google's "I Feel Lucky" button (https://www.google.com/)? – QualiT Jan 11 '19 at 22:26
  • As you can see in the link there is no element I need to click on. just enter the characters and press enter is the only option. – vivek.sahni Jan 12 '19 at 06:11
  • Tried with above code. It still doesn't work. Can you please try the above link at your end and see where is the issue? I shall be thankful to you for this :) – vivek.sahni Jan 13 '19 at 14:14
  • Ah, useful thank you. I have updated the description with another option. – QualiT Jan 14 '19 at 06:39
  • I'm also curious what version of nightwatch you are using and what browser you're testing with. Selenium version might also be relevant. If you are using Chrome, add the version of Chrome and the Chromedriver – QualiT Jan 14 '19 at 06:41
  • I am using chromedriver latest version (ChromeDriver 2.45), selenium-server-standalone-3.14.0 jar and nightwatch v1.0.18, Chrome Version 71.0.3578.98 (Official Build) (64-bit) – vivek.sahni Jan 14 '19 at 16:30
  • Apologies, I have been pulled into other work and haven't had time to look into this. I recall from past experience that .keys wasn't always reliable when I last used it, but in my search for how I handled it I have come up empty because those repos are not mine anymore. Though after looking at my Stackoverflow history, my suspicion is that option 2 at on this will work for you: https://stackoverflow.com/a/48775667/3182958 – QualiT Jan 16 '19 at 21:18