本文来自网易云社区
作者:陶奎
Robot robot = null;
try {
robot = new Robot();
robot.keyPress(java.awt.event.KeyEvent.VK_ALT);
robot.keyPress(java.awt.event.KeyEvent.VK_S);
robot.keyRelease(java.awt.event.KeyEvent.VK_S);
robot.keyPress(java.awt.event.KeyEvent.VK_S);
robot.keyRelease(java.awt.event.KeyEvent.VK_S);
robot.keyRelease(java.awt.event.KeyEvent.VK_ALT);
robot.keyPress(java.awt.event.KeyEvent.VK_ENTER);
robot.keyRelease(java.awt.event.KeyEvent.VK_ENTER);
} catch (AWTException e) {
e.printStackTrace();
}
ProfilesIni pi = new ProfilesIni();
FirefoxProfile fp = pi.getProfile("default"); //使用用户默认的配置
DesiredCapabilities dc = DesiredCapabilities.firefox();
// fp.setPreference("media.navigator.video.preferred_codec", "126");
dc.setCapability(FirefoxDriver.PROFILE, fp);
WebDriver driver = new FirefoxDriver(dc);
Robot robot = null;
try {
robot = new Robot();
robot.keyPress(java.awt.event.KeyEvent.VK_CONTROL);
robot.keyPress(java.awt.event.KeyEvent.VK_U);
robot.keyRelease(java.awt.event.KeyEvent.VK_U);
robot.keyRelease(java.awt.event.KeyEvent.VK_CONTROL);
} catch (AWTException e) {
e.printStackTrace();
}
try {
Thread.sleep(1000); //需要添加SleepTime等待页面打开来
} catch (InterruptedException e) {
e.printStackTrace();
}
ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles());
driver.switchTo().window(tabs.get(i)); //Driver切换到新的标签页
driver.get(webDemoInst.getJoinUrl());//新标签页打开URL
网易云免费体验馆,0成本体验20+款云产品!
更多网易研发、产品、运营经验分享请访问网易云社区。