【问题标题】:What does 'the key input state' mean in the Webdriver spec?Webdriver 规范中的“键输入状态”是什么意思?
【发布时间】:2020-11-30 09:22:39
【问题描述】:

我一直在尝试消化Webdriver specits more friendly version。而且我无法理解这些词的含义(在 'Element Send Keys' 命令的描述中):

用于输入的键输入状态可以清除在“打字”中途通过发送空键,即U+E000(NULL)

我对这可能意味着什么有几个想法,我在下面提到一些作为我“先前研究”的证据*)。

谁能解释一下这是什么意思,如果可能的话,举个例子,最好是用 JavaScript 吗?


*尝试自己解决: 我想,如果他之前按下了 Shift 键,可能会跳过调用releaseActions(),例如:

await browser.performActions([
  {
    type: 'key',
    id: 'key1',
    actions: [
      { type: 'keyDown', value: '\u0010', },
    ],
  },
]);
await browser.elementSendKeys(elemUUID, '\uE000ABC');

但是不,当调用elementSendKeys() 时,Shift 键仍然被按下。

我还认为空字符会清除元素中的文本,不,它不会。

【问题讨论】:

    标签: testing webdriver automated-tests webdriver-io


    【解决方案1】:

    我最初关于单词含义的想法是正确的,只是测试它的示例有错误。

    从抽象的角度来看,需要了解spec 是如何定义Actions API 的。简单来说就是这样:

    在 Webdriver 实现环境中,有一定的输入源,如 null、键盘、指针(可能还有其他)。每个输入源都有一个关联的 input state 对象,它(简化)是源的当前状态,例如(对于键盘源)现在正在按住哪些键,或者(对于指针来源)光标现在在屏幕上的什么位置等。

    因此,如果执行keyDownkeyboard 操作,则该键将保持按下状态,直到执行该键的keyUp 操作或状态被重置。

    null unicode 代码点可用于字符串文字以重置键盘输入源的状态,即释放所有当前按住的键。

    这是一个例子:

    // elemUUID can be taken from the return values
    // of methods like `findElement()` etc.
    
    await browser.performActions([
      {
        type: 'key',
        id: 'key1',
        actions: [
          // \u0008 is used for a Shift key in Webdriver
          // I don't actually know, where it's specified
          { type: 'keyDown', value: '\u0008', },
        ],
      },
    ]);
    
    // Here the remote end (the automated browser)
    // will type a capital A, since the shift key
    // is still being pressed
    await browser.elementSendKeys(elemUUID, 'a');
    
    // One can include the null char somewhere in
    // the string, and all subsequent chars will be
    // 'pressed' without the pressed Shift
    // This will type Aa
    await browser.elementSendKeys(elemUUID, 'a\uE000a');
    

    在我的问题示例中,错误是:Shift 键的 Unicode 代码点值错误,以及 elementSendKeys() 方法的文本参数中的大写字母,这使得驱动程序使用 Shift 键,尽管空字符有已提供,即在:

    await browser.elementSendKeys(elemUUID, '\uE000A');
    

    Shift 键总是被按下,因为 'A' 暗示它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-08
      相关资源
      最近更新 更多