public void UpFileOne() throws AWTException {
driver.get("mkgerenxinxibianji");//打开个人信息编辑
WebElement HeadPng = driver.findElement(By.className("avator-mode"));//定位到当前登录头像
Actions action = new Actions(driver);
action.moveToElement(HeadPng).perform();//移动鼠标
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.findElement(By.className("js-avator-link")).click();//点击更换头像
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.findElement(By.className("avator-btn-fake")).click();//点击上传头像按钮
/**
* 复制输入要上传的文件地址
*/
StringSelection selectJpg = new StringSelection("要上传文件的地址");
Clipboard sysc = Toolkit.getDefaultToolkit().getSystemClipboard();
sysc.setContents(selectJpg, null);
/**
* 模拟键盘进行剪切操作,将复制的文件地址剪切
*/
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);//按住Ctrl键
robot.keyPress(KeyEvent.VK_V);//按住v键
robot.keyRelease(KeyEvent.VK_V);//释放Ctrl键
robot.keyRelease(KeyEvent.VK_CONTROL);//释放v键
robot.keyPress(KeyEvent.VK_ENTER);//按住Enter确认键
robot.keyRelease(KeyEvent.VK_ENTER);//释放Enter键
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
driver.close();
}