升级到 Selenium 4。无法在 nightwatch 中按住 Control + 单击

问题描述 投票:0回答:1

我希望这里有人可以帮助我解决我在自动化测试中遇到的这个问题。

我正在用 Nightwatch 进行测试。

我正在升级到 Selenium 4。除了一个问题之外,一切正常。我在脚本中所做的一件事是控制单击和 Shift 单击。我需要有一个新选项卡或新窗口来进行测试。

到目前为止(在 selenium 3 中)我会这样编码: client.keys(client.Keys.SHIFT) 或 client.keys(client.Keys.CONTROL) 然后我会执行单击命令。这将在新选项卡或窗口中打开链接。 我也尝试只做 Keys.CONTROL (省略客户端这个词)它似乎没有什么区别。

自从我升级以来,它不会在新选项卡中打开。链接打开,但忽略了我单击 CONTROL 的事实。

我使用 webdriver 或 selenium-webdriver 尝试了许多不同的组合,如图所示。

const driver1 = require("webdriver"); const driver2 = require('selenium-webdriver')

driver1.actions().keyDown(Keys.SHIFT).perform(); 我收到此错误: driver1.actions 不是函数

driver1.actions.keyDown(Keys.SHIFT).perform(); 我收到此错误:无法读取未定义的属性(读取“keyDown”)

driver2.Actions.keyDown(client.Keys.CONTROL).perform() 我收到此错误:无法读取未定义的属性(读取“keyDown”)

client.keys(client.Keys.CONTROL) 或 client.keys(Keys.CONTROL) 然后单击:忽略 CONTROL,只需单击

任何提示将不胜感激!!

谢谢!!!

selenium-webdriver automated-tests nightwatch.js
1个回答
0
投票

您需要在 Selenium 中执行以下操作

await driver.actions()
        .keyDown(Key.SHIFT)
        .sendKeys('a')
        .perform()

在 NightwatchJS 中你会执行以下操作

describe('example with user actions api', function () {
  
  before(browser => browser.navigateTo('https://nightwatchjs.org'));
  
  it('demo test', async function (browser) {
    // retrieve the element; the actions api requires Selenium WebElement objects,
    //  which can be retrieved using the global element() utility
    const btnElement = await element('a.btn-github').findElement();
    
    await browser.perform(function() {
      // initiate the actions chain
      const actions = this.actions({async: true});
      
      return actions
        .<insert commands>
    });
  });
});
© www.soinside.com 2019 - 2024. All rights reserved.