//通过Robot对象完成按键操作
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
public class RobotTest {
WebDriver driver;
String url="https://www.baidu.com";
@Test
public void TestDemo() throws InterruptedException {
driver.get(url);
WebDriverWait wait = new WebDriverWait(driver,10);
//显式等待
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("kw")));
driver.findElement(By.id("kw