@Test
public void login() {
//打开网页
driver.get("http://www.guoyasoft.com:8080/guoya-client/jsp/user/login.jsp");
//定位元素,输入用户名
WebElement userName = driver.findElement(By.xpath("//input[@id=\"userName\"]"));
userName.clear();
userName.sendKeys("guhy");
//定位元素,输入密码
WebElement password = driver.findElement(By.xpath("//input[@id=\"password\"]"));
password.clear();
password.sendKeys("254422");
sleep(2);
//点击登录
WebElement loginBtn = driver.findElement(By.xpath("//input[@id=\"loginBtn\"]"));
click(loginBtn);
sleep(1);
//定位,上传总结,点击
driver.findElement(By.xpath("//a[text()='上传总结1811A']")).click();
//切换iframe框
WebElement iframe = driver.findElement(By.xpath("//iframe[@id=\"iframepage\"]"));
driver.switchTo().frame(iframe);
sleep(1);
//定位姓名框
driver.findElement(By.xpath("//select[@id=\"sno\"]"));
//点击下拉框
WebElement select=driver.findElement(By.xpath("//select"));
Select selects=new Select(select);
selects.selectByVisibleText("170_顾虹雁");
sleep(1);
//选择文件点击,上传作业路径(桌面上传的图片右击属性,属性文件路径)
driver.findElement(By.xpath("//input[@id=\"postFild\"]")).sendKeys("C:\\Users\\guoya\\Desktop\\全部\\2.png");
sleep(2);
//定位,点击上传总结,点击
driver.findElement(By.xpath("//input[@id=\"uploadFileBtn\"]")).click();
//切换到alert弹框
Alert alert = driver.switchTo().alert();
alert.accept();
driver.switchTo().defaultContent();
//定位,作业检查,点击
driver.findElement(By.xpath("//a[text()='作业检查1811A']")).click();
sleep(1);
//切出iframe框
WebElement Iframe = driver.findElement(By.xpath("//iframe[@id=\"iframepage\"]"));
driver.switchTo().frame(Iframe);
//判断当前如果不为√,点击
driver.findElement(By.xpath("//img[@id=\"170_img\"]")).click();
}
打开网址

image.png
上传总结流程

image.png
选择文件点击,上传作业路径(桌面上传的图片右击属性,属性文件路径)

image.png
判断当前如果不为√,点击

image.png

image.png
切换iframe框

image.png