Node.JS selenium 发送 key 回车

标签 node.js selenium

当我在 Node js 中发送返回键时它给出错误?

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

所有网站都告诉我这是我需要使用的?请帮忙

最佳答案

我假设您正在使用 npm 包 Selenium Webdriver:https://www.npmjs.com/package/selenium-webdriver

Keys is not defined 错误是因为你在使用前没有定义keys。您需要使用枚举 key ( https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_Key.html )

它是驱动程序模块上的常量,并作为 Key 导出(注意单数形式)。我已将更新后的代码放在下面。

const driver = require('selenium-webdriver')

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

额外提示:我一直在使用 http://webdriver.io/而且它比这个库更容易使用

关于Node.JS selenium 发送 key 回车,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41428871/

相关文章:

node.js - 如何计算 TOTP 到期的秒数?

javascript - 为什么使用await & EventEmitter时nodejs程序会退出?

java - 使用 Selenium Webdriver 在网页中移动鼠标

node.js - 向我的 sequelize 查询添加限制会引发错误

javascript - Mongoose 不加入两个集合

javascript - 使用 Selenium C# 将 Chrome 缩放设置为 100%

java - 无法通过 xpath 找到要选择的元素

php - 更改窗口大小 PHPUnit Selenium2TestCase

node.js - 如何等待索引健康状况

jquery - 需要帮助确定关闭弹出窗口的正确元素标识