如何让WebdriverIO在输入框中缓慢输入

dam*_*tch 3 testing selenium automated-tests webdriver-io

我正在使用 WebdriverIO 编写测试用例,我注意到为输入设置值的唯一方法是使用setValue. 这实际上设置了输入框的全部值。然而,我需要的是将字符一一输入到输入中。我需要这样做,因为我正在测试的元素会在您键入时显示 drodpown 选项。当我使用setvalue这些选项时,不会出现,因为它只是将值复制到输入。

小智 7

您可以输入带有停顿的单个字符。(我在使用 webdriverIO 时遇到此问题时的经验)

前:

const value = "Auto- This note is created from automation at 09-05-2020 12:48 PM"
$(selector).setValue(value)
Run Code Online (Sandbox Code Playgroud)

它在 UI 字段中输入类似这样的内容:

 9-05-20is created from automAuto-This note tion at 020 12:48 PM
Run Code Online (Sandbox Code Playgroud)

为了降低打字速度,我将字符串的每个字符传递给keys()方法,并在这些字符传递之间放置一个暂停。

const value = "Auto- This note is created from automation at 09-05-2020 12:48 PM"
const arrValue = [...value]; // This is for converting string to charArray

for(let i = 0 ; i< arrValue.length; i++) {
browser.keys(arrValue[i] );
browser.pause(200); // .5 milisecond pause
Run Code Online (Sandbox Code Playgroud)

输出:

Auto- This note is created from automation at 09-05-2020 12:48 PM
Run Code Online (Sandbox Code Playgroud)