This commit is contained in:
tqzhang 2024-07-19 18:21:19 +08:00
parent 1125e46314
commit 3858f07436
3 changed files with 21 additions and 23 deletions

View File

@ -34,22 +34,20 @@ public class AutoMain {
*/ */
public void initDrive(int type) { public void initDrive(int type) {
// chromedriver服务地址 // chromedriver服务地址
try{
System.setProperty(DataConfig.DRIVE_NAME, DataConfig.drivePath); System.setProperty(DataConfig.DRIVE_NAME, DataConfig.drivePath);
ChromeOptions option = new ChromeOptions(); ChromeOptions option = new ChromeOptions();
//添加浏览器地址 //添加浏览器地址
// option.setBinary("C:\\Program Files\\Mozilla Firefox\\firefox.exe");//个人本地
// option.setBinary("C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe");//个人本地
option.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"); option.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
// option.setBinary("C:\\Users\\Administrator\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe");//宿州
// option.addArguments("start-fullscreen");
option.addArguments("--start-maximized"); option.addArguments("--start-maximized");
option.addArguments("--force-device-scale-factor=0.75"); option.addArguments("--force-device-scale-factor=0.75");
option.addArguments("disable-infobars"); option.addArguments("disable-infobars");
//隐藏页面 //隐藏页面
// option.addArguments("--headless");
// webDriver = new FirefoxDriver(option);
webDriver = new ChromeDriver(option); webDriver = new ChromeDriver(option);
}catch (Exception e){
e.printStackTrace();
log.error("初始化驱动失败");
}
} }
/** /**

View File

@ -116,7 +116,7 @@ public class DutyLogIOp {
td = dayNum - 1; td = dayNum - 1;
} }
log.info("标签位置tr:" + tr + "td:" + td); log.info("标签位置tr:" + tr + "td:" + td);
xpath = "//*[@id=\"app\"]/div/section/main/div/div[1]/div[1]/div[3]/div[2]/table/tbody/tr[" + tr + "]" + "/td[" + td + "]/div"; xpath = "//*[@id=\"app\"]/div/section/main/div/div[1]/div[1]/div[3]/div[2]/table/tbody/tr[" + tr + "]" + "/td[" + td + "]";
} else { } else {
//点击上月按钮切换至上月 //点击上月按钮切换至上月
webDriver.findElement(By.xpath("//*[@id=\"app\"]/div/section/main/div/div[1]/div[1]/div[3]/div[1]/div[2]/div/button[1]")).click(); webDriver.findElement(By.xpath("//*[@id=\"app\"]/div/section/main/div/div[1]/div[1]/div[3]/div[1]/div[2]/div/button[1]")).click();
@ -128,7 +128,7 @@ public class DutyLogIOp {
//判断上个月最后一天的位置 //判断上个月最后一天的位置
tr = DateTimeUtils.getWeekNum(mothDay); tr = DateTimeUtils.getWeekNum(mothDay);
td = DateTimeUtils.getWeekOfDate(mothDay); td = DateTimeUtils.getWeekOfDate(mothDay);
xpath = "//*[@id=\"app\"]/div/section/main/div/div[1]/div[1]/div[3]/div[2]/table/tbody/tr[" + tr + "]" + "/td[" + td + "]/div"; xpath = "//*[@id=\"app\"]/div/section/main/div/div[1]/div[1]/div[3]/div[2]/table/tbody/tr[" + tr + "]" + "/td[" + td + "]";
// String dayNum = mothDay.substring(8, 10); // String dayNum = mothDay.substring(8, 10);
// WebElement spanElement = webDriver.findElement(By.xpath("//*[@id=\"app\"]/div/section/main/div/div[1]/div[1]/div[3]/div[2]/table/tbody/tr[" + tr + "]" + "/td[" + td + "]/div/div/div[1]/span")); // WebElement spanElement = webDriver.findElement(By.xpath("//*[@id=\"app\"]/div/section/main/div/div[1]/div[1]/div[3]/div[2]/table/tbody/tr[" + tr + "]" + "/td[" + td + "]/div/div/div[1]/span"));
// if (dayNum.equals(spanElement.getText())) { // if (dayNum.equals(spanElement.getText())) {

View File

@ -165,10 +165,10 @@ public class AutoWebTask {
"]/table/tbody/tr[2]/td[2]/div/div/p[1]")); "]/table/tbody/tr[2]/td[2]/div/div/p[1]"));
String personName = personNameEle.getText(); String personName = personNameEle.getText();
log.info("今日值班人员:" + personName); log.info("今日值班人员:" + personName);
WebElement accountEle = webDriver.findElement(By.xpath("//*[@id='pane-1']/div/div[3]/div/div/div[3" + // WebElement accountEle = webDriver.findElement(By.xpath("//*[@id='pane-1']/div/div[3]/div/div/div[3" +
"]/table/tbody/tr[2]/td[2]/div/div/p[2]")); // "]/table/tbody/tr[2]/td[2]/div/div/p[2]"));
String account = accountEle.getText(); // String account = accountEle.getText();
log.info("今日值班人员账号:" + account); // log.info("今日值班人员账号:" + account);
Thread.sleep(3000); Thread.sleep(3000);
excelFile = new FileInputStream("E:\\bns\\config\\zhibanaccount.xlsx"); excelFile = new FileInputStream("E:\\bns\\config\\zhibanaccount.xlsx");
workbook = new XSSFWorkbook(excelFile); workbook = new XSSFWorkbook(excelFile);
@ -179,7 +179,7 @@ public class AutoWebTask {
value += cell.getStringCellValue() + "]]]"; value += cell.getStringCellValue() + "]]]";
} }
value = value.substring(0, value.length() - 3); value = value.substring(0, value.length() - 3);
if (value.contains(account)) { if (value.contains(personName)) {
System.out.println("今天:" + value); System.out.println("今天:" + value);
AutoUtils.write("E:\\bns\\config\\今日值班账号.txt", "今日账号:" + value.split("]]]")[1] + ";密码:" + value.split( AutoUtils.write("E:\\bns\\config\\今日值班账号.txt", "今日账号:" + value.split("]]]")[1] + ";密码:" + value.split(
"]]]")[2]); "]]]")[2]);