TA的每日心情 | 开心 2021-4-27 13:59 |
---|
签到天数: 184 天 连续签到: 1 天 [LV.7]测试师长
|
这个我笔记本是fn+F12的,不知道你是不是也是,所以单纯用action是驱动不起来的。
所以我改用Robot了。package test;
import java.awt.AWTException;
import java.awt.Robot;
import java.awt.event.KeyEvent;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class F12 {
public static WebDriver driver=null;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
System.setProperty("webdriver.chrome.driver","C:\\browserdriver\\chromedriver.exe");
driver=new ChromeDriver();
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
driver.quit();
}
@Test
public void test() throws InterruptedException, AWTException {
driver.get("https://www.baidu.com/");
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_F12);
robot.keyRelease(KeyEvent.VK_F12);
Thread.sleep(3000);
}
}
|
|