Selenium 模拟人输入

时间:2023-03-08 19:38:33
Selenium 模拟人输入
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