2017-01-02 142 views
2

当我在nodejs中发送reutn密钥时,它会给出错误?Node.JS硒发送密钥输入

driver.findElement(By.id('twofactorcode_entry')).sendKeys(Keys.ENTER); 

所有的网站告诉我,这是我需要使用?任何帮助,请

+0

这是什么给出了错误使用? –

+0

@PeterGrainger它说的钥匙没有定义 –

+0

看到下面的答案 –

回答

6

我假设你正在使用NPM包硒的webdriver:https://www.npmjs.com/package/selenium-webdriver

错误按键没有定义是因为你还没有使用它之前定义的键。您需要使用枚举键(https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_Key.html

它是驱动程序模块上的一个常量,并以键的形式导出(注意单数形式)。我已经把更新的代码放在下面。

const driver = require('selenium-webdriver'); 


driver.findElement(By.id('twofactorcode_entry')).sendKeys(driver.Key.ENTER); 

额外提示:我一直在使用http://webdriver.io/,这是一个更容易一些比这个库