From 9d46f884bcc0701cb1edc1c744971d1b74ea248a Mon Sep 17 00:00:00 2001 From: zfh <15856818120@163.com> Date: Fri, 28 Feb 2025 16:27:11 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bonus/autoweb/base/DutyChangeShifts.java | 15 ++++- .../com/bonus/autoweb/base/DutyClock.java | 64 ++++++++++++++----- .../com/bonus/autoweb/base/DutyLogIOp.java | 17 ++++- 3 files changed, 77 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/bonus/autoweb/base/DutyChangeShifts.java b/src/main/java/com/bonus/autoweb/base/DutyChangeShifts.java index be3c748..c6f7f0a 100644 --- a/src/main/java/com/bonus/autoweb/base/DutyChangeShifts.java +++ b/src/main/java/com/bonus/autoweb/base/DutyChangeShifts.java @@ -70,7 +70,18 @@ public class DutyChangeShifts { //交接事项说明 if (type == 1) { // /html/body/div[3]/div/div[2]/div/form/div[7]/div/div[1]/textarea - webDriver.findElement(By.xpath("/html/body/div[3]/div/div[2]/div/form/div[2]/div/div[1]/textarea")).sendKeys("正常"); + + try { + webDriver.findElement(By.xpath("/html/body/div[3]/div/div[2]/div/form/div[2]/div/div[1]/textarea")).sendKeys("正常"); + }catch (Exception e){ + log.info("交接事项说明div[3]不存在----------"); + } + + try { + webDriver.findElement(By.xpath("/html/body/div[8]/div/div[2]/div/form/div[2]/div/div[1]/textarea")).sendKeys("正常"); + }catch (Exception e){ + log.info("交接事项说明div[8]不存在----------"); + } log.info("交接事项说明----------"); Thread.sleep(500); //提交 @@ -175,4 +186,4 @@ public class DutyChangeShifts { } -} \ No newline at end of file +} diff --git a/src/main/java/com/bonus/autoweb/base/DutyClock.java b/src/main/java/com/bonus/autoweb/base/DutyClock.java index b79820c..4acac89 100644 --- a/src/main/java/com/bonus/autoweb/base/DutyClock.java +++ b/src/main/java/com/bonus/autoweb/base/DutyClock.java @@ -12,7 +12,7 @@ import org.slf4j.Logger; * 值班打卡 */ public class DutyClock { - private Logger log = LoggerFactory.getLogger(DutyClock.class); + private Logger log = LoggerFactory.getLogger(DutyClock.class); private WebDriver webDriver; @@ -21,9 +21,8 @@ public class DutyClock { } - public void openDutyClock() throws InterruptedException { - Thread.sleep(1000*4); + Thread.sleep(1000 * 4); //定位值班打卡并点击 webDriver.findElement(By.id("tab-2")).click(); log.info("定位值班打卡并点击----------"); @@ -64,14 +63,47 @@ public class DutyClock { xpaht = "//*[@id=\"pane-2\"]/div/div[3]/div[2]/div[1]/div[2]/button[2]"; } } - Thread.sleep(1000*4); + + Thread.sleep(1000 * 4); webDriver.findElement(By.xpath(xpaht)).click(); log.info("打卡签到----------"); - Thread.sleep(1000*5); + Thread.sleep(1000 * 5); + + //判断是否有相应的元素 + try { + Thread.sleep(2000); + webDriver.findElement(By.xpath("html/body/div[2]/div/div[3]/button[2]")).click(); + log.info("确认提前签到div[2]----------"); + } catch (Exception e) { + log.info("无确认框,在时间范围内----------"); + } + + //判断是否有相应的元素 + try { + Thread.sleep(2000); + webDriver.findElement(By.xpath("html/body/div[6]/div/div[3]/button[2]")).click(); + log.info("确认提前签到div[6]----------"); + } catch (Exception e) { + log.info("无确认框,在时间范围内----------"); + } + + + try { + //点击弹出框确认 + webDriver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div[2]/div[1]")).click(); + } catch (Exception e) { + log.info("当前打卡确认按钮不存在div[2]"); + } + try { + //点击弹出框确认 + webDriver.findElement(By.xpath("/html/body/div[3]/div/div[2]/div/div[2]/div[1]")).click(); + } catch (Exception e) { + log.info("当前打卡按钮不存在div[3]"); + } //点击弹出框确认 - webDriver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div[2]/div[1]")).click(); +// webDriver.findElement(By.xpath("/html/body/div[2]/div/div[2]/div/div[2]/div[1]")).click(); log.info("点击弹出框确认----------"); Thread.sleep(800); } @@ -99,19 +131,19 @@ public class DutyClock { td = dayNum - 1; }*/ if (dayNum == 1) { - if(DateTimeUtils.getMonthOneDayIs0()){//第一天是0 + if (DateTimeUtils.getMonthOneDayIs0()) {//第一天是0 tr = weekNum; - }else{ - tr = weekNum-1; - if (weekNum == 1){ + } else { + tr = weekNum - 1; + if (weekNum == 1) { tr = 5; } } td = 7; - }else { - if(DateTimeUtils.getMonthOneDayIs0()){//第一天是0 - tr = weekNum+1; - }else{ + } else { + if (DateTimeUtils.getMonthOneDayIs0()) {//第一天是0 + tr = weekNum + 1; + } else { tr = weekNum; } td = dayNum - 1; @@ -124,7 +156,7 @@ public class DutyClock { Thread.sleep(300); //获取上月最后一天日期 - String mothDay=DateTimeUtils.getBeforeLastMonthdate(); + String mothDay = DateTimeUtils.getBeforeLastMonthdate(); //判断上个月最后一天的位置 tr = DateTimeUtils.getWeekNum(mothDay); td = DateTimeUtils.getWeekOfDate(mothDay); @@ -144,7 +176,7 @@ public class DutyClock { Thread.sleep(3000); //进行晚班签退操作 log.info("进行晚班签退操作----------"); - dutyClockOper(2,2); + dutyClockOper(2, 2); Thread.sleep(300); diff --git a/src/main/java/com/bonus/autoweb/base/DutyLogIOp.java b/src/main/java/com/bonus/autoweb/base/DutyLogIOp.java index 02b097c..2cac4ce 100644 --- a/src/main/java/com/bonus/autoweb/base/DutyLogIOp.java +++ b/src/main/java/com/bonus/autoweb/base/DutyLogIOp.java @@ -349,6 +349,21 @@ public class DutyLogIOp { log.info("提交日志----------"); Thread.sleep(2000); + //判断是否有相应的元素 + try{ + Thread.sleep(2000); + webDriver.findElement(By.xpath("html/body/div[3]/div/div[3]/button[2]")).click(); + log.info("是否确认签到----------"); + }catch (Exception e){ + log.info("无确认框,在时间范围内div[3]----------"); + } + try{ + Thread.sleep(2000); + webDriver.findElement(By.xpath("html/body/div[4]/div/div[3]/button[2]")).click(); + log.info("是否确认签到----------"); + }catch (Exception e){ + log.info("无确认框,在时间范围内div[4]----------"); + } //点击弹出框确认 /html/body/div[4]/div/div[3]/button[2] WebElement qrBtn = webDriver.findElement(By.xpath("/html/body/div[4]/div/div[3]/button[2]")); @@ -379,7 +394,7 @@ public class DutyLogIOp { WebElement dutyIframe = webDriver.findElement(By.id("zbgln")); webDriver.switchTo().frame(dutyIframe); log.info("定位值班管理iframe的标签----------"); - Thread.sleep(500); + Thread.sleep(3000); }