package com.bw.model;
import java.util.List;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.By.ByClassName;
import org.openqa.selenium.NoAlertPresentException;
import org.openqa.selenium.UnexpectedAlertBehaviour;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.Select;
import org.testng.annotations.Test;
public class UserManager {
WebDriver driver;
public static void main(String[] args) throws InterruptedException {
UserManager fr = new UserManager();
fr.initwebderiver();
}
//初始化驱动
public void initwebderiver() throws InterruptedException {
boolean flag=false;
int count=0;
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR,UnexpectedAlertBehaviour.IGNORE);
System.setProperty("webdriver.firefox.bin", "C://Program Files (x86)//Mozilla Firefox//firefox.exe");
driver = new FirefoxDriver(dc);
//driver.get("http://123.56.92.221/mainsite/src/html/login/login.html");
//driver.get("http://10.100.3.2/mainsite/src/html/login/login.html");
driver.get("http://www.baiwang.com/mainsite/src/html/login/login.html");
//driver.get("http://10.100.3.2/output/output/sysmgmt/userMgmt");
driver.findElement(By.id("username")).sendKeys("cpy001");
driver.findElement(By.id("password")).sendKeys("a123456");
driver.findElement(By.id("login-btn")).click();
Thread.sleep(18000);
//tab页面切换
List
list.get(4).click();
Thread.sleep(6000);
driver.manage().window().maximize();
adduser();
}
//删除用户
public void delete() throws InterruptedException {
driver.findElement(By.xpath("//span[text()='查询']")).click();
List
for(int i=0;i
delete.get(i).click();
Thread.sleep(4000);
break;
}
}
Thread.sleep(4000);
List
System.out.println(comfire.size());
for(int j=0;j
comfire.get(j+1).click();
break;
}
}
}
//添加用户
@Test
public void run() throws InterruptedException {
adduser();
search();
}
public void adduser() throws InterruptedException {
driver.findElement(By.xpath("//span[text()='添加用户']")).click();
Thread.sleep(7000);
List
System.out.println("点击了添加按钮");
int count=0;
for(int i=0;i
if(i>1) {
String[] inputinfo= {"cpy00123","开发","shixinfa","testpart","15510225994","[email protected]"};
listinfo.get(i).sendKeys(inputinfo[i-13]);
count++;
}
}
}
driver.findElement(By.xpath("//span[text()='下一步']")).click();
List
//driver.findElements(By.className("ivu-checkbox-input"));
System.out.println(checkbox.size());
for(int i=0;i
checkbox.get(i).click();
}
}
Thread.sleep(16000);
driver.findElement(By.xpath("//div/div[2]/ul/li/label/span/input")).click();
Thread.sleep(14000);
driver.findElement(By.xpath("//form[2]/div/div/div/div/div/div[2]/ul/li/div/div/ul[4]/li/label/span/input")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//div[2]/div/div/div[3]/div/button[3]/span")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//div/div/div[3]/div/button[5]")).click();
//li/div/div/ul[3]/li/label/span/input
// driver.findElement(By.cssSelector("body > div:nth-child(12) > div.ivu-modal-wrap.addUserBox > div > div > div.ivu-modal-body > div.usermgmt_mdel > form:nth-child(2) > div > div > div > div > div > div.tree_node_box > ul > li > label > span > input")).click();
/*for(int i=0;i
if(checkbox.get(i).getAttribute("type")=="checkbox") {
checkbox.get(i).click();
}
// System.out.println(checkbox.get(i).getAttribute("className"));
System.out.println(checkbox.get(i).getAttribute("type"));
}*/
}
//查詢數據
public void search() throws InterruptedException {
List
System.out.println(search.size());
/* for(int k=0;k
System.out.println("进入到It行业");
}*/
//System.out.println(search.get(k).getAttribute("placeholder")+search.get(k).getAttribute("autocomplete"));
search.get(0).sendKeys("cpy001");
search.get(1).sendKeys("测试40");
driver.findElement(By.className("bw-chaxun")).click();
Thread.sleep(2000);
}
//編輯數據
public void edituser() throws InterruptedException {
driver.findElement(By.xpath("//span[text()='添加用户']")).click();
Thread.sleep(7000);
List
System.out.println("点击了添加按钮");
int count=0;
for(int i=0;i
if(i>1) {
String[] inputinfo= {"cpy00123","开发","shixinfa","testpart","15510225994","[email protected]"};
listinfo.get(i).sendKeys(inputinfo[i-13]);
count++;
}
}
}
driver.findElement(By.xpath("//span[text()='下一步']")).click();
List
//driver.findElements(By.className("ivu-checkbox-input"));
System.out.println(checkbox.size());
for(int i=0;i
checkbox.get(i).click();
}
}
Thread.sleep(12000);
driver.findElement(By.xpath("//div/div[2]/ul/li/label/span/input")).click();
Thread.sleep(14000);
driver.findElement(By.xpath("//form[2]/div/div/div/div/div/div[2]/ul/li/div/div/ul[4]/li/label/span/input")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//div[2]/div/div/div[3]/div/button[3]/span")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//div/div/div[3]/div/button[5]")).click();
//li/div/div/ul[3]/li/label/span/input
// driver.findElement(By.cssSelector("body > div:nth-child(12) > div.ivu-modal-wrap.addUserBox > div > div > div.ivu-modal-body > div.usermgmt_mdel > form:nth-child(2) > div > div > div > div > div > div.tree_node_box > ul > li > label > span > input")).click();
/*for(int i=0;i
if(checkbox.get(i).getAttribute("type")=="checkbox") {
checkbox.get(i).click();
}
// System.out.println(checkbox.get(i).getAttribute("className"));
System.out.println(checkbox.get(i).getAttribute("type"));
}*/
}
}