when i send a the reutn key in nodejs it gives a error?
driver.findElement(By.id('twofactorcode_entry')).sendKeys(Keys.ENTER);
All the sites tell me this is what i need to use? any help please
I'm assuming you are using npm package Selenium Webdriver: https://www.npmjs.com/package/selenium-webdriver
The error Keys is not defined occurs because you haven't defined keys before using it. You need to use the Enum Key (https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_Key.html)
It is a constant on the driver module and exported as Key (note the singular form). I've put the updated code below.
const driver = require('selenium-webdriver')
driver.findElement(By.id('twofactorcode_entry')).sendKeys('webdriver', driver.Key.ENTER);
Extra tip: I've been using http://webdriver.io/ and it's a little easier to use than this library
For some reason the other solutions didn't work for me.
Using Node.js, it seems you can just use \n
for enter:
await driver.findElement(By.id('my-field-id')).sendKeys('my-value\n');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With