TA的每日心情 | 擦汗 2016-12-20 19:03 |
---|
签到天数: 11 天 连续签到: 1 天 [LV.3]测试连长
|
4#
楼主 |
发表于 2016-4-1 08:07:42
|
只看该作者
public String selectDepartmentForAddEmployee(WebDriver driver) {
// 点击了一级部门
int num1 = getElements(driver, By.xpath("//li[@level='1']"));
// logD("一级部门有:" + num1 + "个");
int rDemt = getIndex(num1) / 2 + 1;
driver.findElement(By.cssSelector("#dName")).click();
delay(500);
// 点击第一层
String xpath = String.format("//*[@id='userModal']/form/div/div/div[2]/div/div[3]/div/div/ul/ul/li[%d]/i[1]",
rDemt);
String xpath_1 = String.format("//*[@id='userModal']/form/div/div/div[2]/div/div[3]/div/div/ul/ul/li[%d]",
rDemt);
// logD("一级菜单的地址为: 【" + rDemt + "】【" + xpath + "】");
clickByxpath(driver, xpath, 500);
// check 第二层是否存在,如果不存在则返回
int num2 = getElements(driver, By.xpath("//li[@level='2']"));
// logD("二级部门有:" + num2 + "个");
if (num2 > 0) {
int rDemt2 = getIndex(num2) + 1;
String xpath2 = String
.format("//*[@id='userModal']/form/div/div/div[2]/div/div[3]/div/div/ul/ul/ul/li[%d]/i[1]", rDemt2);
String xpath2_1 = String
.format("//*[@id='userModal']/form/div/div/div[2]/div/div[3]/div/div/ul/ul/ul/li[%d]", rDemt2);
// logD("二级菜单的地址为: 【" + rDemt2 + "】【" + xpath2 + "】");
clickByxpath(driver, xpath2, 500);
// check 第三层是否存在,如果不存在则返回
int num3 = getElements(driver, By.xpath("//li[@level='3']"));
// logD("三级部门有:" + num3 + "个");
if (num3 > 0) {
int rDemt3 = getIndex(num3) + 1;
String xpath3 = String.format(
"//*[@id='userModal']/form/div/div/div[2]/div/div[3]/div/div/ul/ul/ul/ul/li[%d]/i[1]", rDemt3);
String xpath3_1 = String.format(
"//*[@id='userModal']/form/div/div/div[2]/div/div[3]/div/div/ul/ul/ul/ul/li[%d]", rDemt3);
// logD("三级菜单的地址为: 【" + rDemt3 + "】【" + xpath3 + "】");
clickByxpath(driver, xpath3, 500);
// check 第四层是否存在,如果不存在则返回
int num4 = getElements(driver, By.xpath("//li[@level='4']"));
// logD("四级部门有:" + num4 + "个");
if (num4 > 0) {
int rDemt4 = getIndex(num4) + 1;
String xpath4 = String.format(
"//*[@id='userModal']/form/div/div/div[2]/div/div[3]/div/div/ul/ul/ul/ul/ul/li[%d]/i[1]",
rDemt4);
String xpath4_1 = String.format(
"//*[@id='userModal']/form/div/div/div[2]/div/div[3]/div/div/ul/ul/ul/ul/ul/li[%d]",
rDemt4);
// logD("四级菜单的地址为: 【" + rDemt4 + "】【" + xpath4 + "】");
clickByxpath(driver, xpath4, 500);
// check 第五层是否存在,如果不存在则返回
int num5 = getElements(driver, By.xpath("//li[@level='5']"));
// logD("五级部门有:" + num5 + "个");
if (num5 > 0) {
int rDemt5 = getIndex(num5) + 1;
String xpath5 = String.format(
"//*[@id='userModal']/form/div/div/div[2]/div/div[3]/div/div/ul/ul/ul/ul/ul/ul/li[%d]/i[1]",
rDemt5);
// logD("五级菜单的地址为: 【" + rDemt5 + "】【" + xpath5 + "】");
clickByxpath(driver, xpath5, 500);
} else {
logD("【四级部门: " + getText(driver, By.xpath(xpath4_1), "data-text") + "】");
return getText(driver, By.xpath(xpath4_1), "data-text");
}
} else {
logD("【三级部门: " + getText(driver, By.xpath(xpath3_1), "data-text") + "】");
return getText(driver, By.xpath(xpath3_1), "data-text");
}
} else {
logD("【二级部门: " + getText(driver, By.xpath(xpath2_1), "data-text") + "】");
return getText(driver, By.xpath(xpath2_1), "data-text");
}
} else {
logD("【一级部门: " + getText(driver, By.xpath(xpath_1), "data-text") + "】");
return getText(driver, By.xpath(xpath_1), "data-text");
}
return null;
}
这是我自己想到的方法,该方法有一个缺点,每次都要刷新一下网页,不然后会出现。 |
|