'the key input state' 在 Webdriver 规范中是什么意思?
What does 'the key input state' mean in the Webdriver spec?
我一直在努力消化 Webdriver spec and its more friendly version。我无法理解这些词的含义(在 'Element Send Keys' 命令的描述中):
The key input state used for input may be cleared mid-way through "typing" by sending the null key, which is U+E000 (NULL)
我对这可能意味着什么有几个想法,我在下面提到一些作为我 'prior research'*) 的一种证据。
谁能解释一下这是什么意思,如果可能的话,最好在JavaScript?
中举个例子
*尝试自己弄明白:
我想,如果他之前按下 Shift 键,可能会跳过调用 releaseActions()
,例如:
await browser.performActions([
{
type: 'key',
id: 'key1',
actions: [
{ type: 'keyDown', value: '\u0010', },
],
},
]);
await browser.elementSendKeys(elemUUID, '\uE000ABC');
但是没有,当elementSendKeys()
被调用时shift键仍然被按下。
我还以为空字符会清除元素中的文本,不,它不会。
我最初的想法是正确的,只是测试它的例子有错误。
从抽象的角度来看,需要理解 spec 如何定义 Actions API。简化一下,就是这样:
在 Webdriver 实现环境中有某些输入源,如 null、键盘、指针(可能是其他)。每个输入源都有一个关联的 输入状态 对象,它(简化)是源的当前状态,例如(对于键盘源)现在正在按住哪些键,或者(对于指针源)光标现在在屏幕上的什么位置等
因此,如果执行 keyDown
键盘操作,则该键将保持按下状态,直到执行该键的 keyUp
操作或重置状态。
可以在字符串文字中使用空 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' 暗示它。
我一直在努力消化 Webdriver spec and its more friendly version。我无法理解这些词的含义(在 'Element Send Keys' 命令的描述中):
The key input state used for input may be cleared mid-way through "typing" by sending the null key, which is U+E000 (NULL)
我对这可能意味着什么有几个想法,我在下面提到一些作为我 'prior research'*) 的一种证据。
谁能解释一下这是什么意思,如果可能的话,最好在JavaScript?
中举个例子*尝试自己弄明白:
我想,如果他之前按下 Shift 键,可能会跳过调用 releaseActions()
,例如:
await browser.performActions([
{
type: 'key',
id: 'key1',
actions: [
{ type: 'keyDown', value: '\u0010', },
],
},
]);
await browser.elementSendKeys(elemUUID, '\uE000ABC');
但是没有,当elementSendKeys()
被调用时shift键仍然被按下。
我还以为空字符会清除元素中的文本,不,它不会。
我最初的想法是正确的,只是测试它的例子有错误。
从抽象的角度来看,需要理解 spec 如何定义 Actions API。简化一下,就是这样:
在 Webdriver 实现环境中有某些输入源,如 null、键盘、指针(可能是其他)。每个输入源都有一个关联的 输入状态 对象,它(简化)是源的当前状态,例如(对于键盘源)现在正在按住哪些键,或者(对于指针源)光标现在在屏幕上的什么位置等
因此,如果执行 keyDown
键盘操作,则该键将保持按下状态,直到执行该键的 keyUp
操作或重置状态。
可以在字符串文字中使用空 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' 暗示它。