selenium键盘事件

2017-09-18  本文已影响0人  鲍尔柯察金

当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();

粘贴前最好等待。

上一篇 下一篇

猜你喜欢

热点阅读