selenium键盘事件

当input文本框的type类型为number时,sendkeys输入方法无效,这时就要模仿键盘先复制再粘贴的方式输入文本。

1.复制:

public static void setClipboardData(String string) {

StringSelection stringSelection = new StringSelection(string);

Toolkit.getDefaultToolkit().getSystemClipboard()

.setContents(stringSelection, null);

}

2.粘贴:

Actions act=new Actions(driver);

act.keyDown(Keys.CONTROL).sendKeys("V").keyUp(Keys.CONTROL).perform();

粘贴前最好等待。

你可能感兴趣的:(selenium键盘事件)