Selenium 模拟人输入

2019-04-13 17:24发布


public
static void type(WebElement e,String str) throws InterruptedException { String[] singleCharacters = str.split(""); // Interval is 0.5 second between each type of character, this is to // simulate real human action for (int i = 0; i < singleCharacters.length; i++) { if (singleCharacters[i]!="") { e.sendKeys(singleCharacters[i]); Thread.sleep(500); } } Thread.sleep(1000); } 在sendKeys时,把字符串拆分成单个字符,使用间隔0.5s