0

Working with selenium-webdriver, I see this type code: await inputField.sendKeys("BrowserStack", Key.ENTER);

Seems that just doing: await inputField.sendKeys("BrowserStack\n"); works just as well (replace Key.ENTER with \n). Is that , or am I missing something?

CodeFinity
  • 1,142
  • 2
  • 19
  • 19

1 Answers1

0

As per Escape Sequences for Character and String Literals:

\ n    /* \u000a: linefeed LF */

Essentially, \n is the escape character for strings that is replaced with the new line object. Writing \n in a string will print out a new line instead of the \n.

Using Selenium similar behaviour can be simulated using either:

  • Key.ENTER
  • Key.RETURN

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Well, it seems to run the test just fine either way. I was guessing that maybe for maximum compatibility with older browsers we might need to spell out `Key.RETURN` instead of just `\n`. But `\n` does trigger, for instance, a submission in browser. – CodeFinity Jul 22 '22 at 23:21
  • 1
    yeap, that's correct, it should behave fine either way. – undetected Selenium Jul 22 '22 at 23:24