From ceaa24dcc5bf76f8df1264643aa822fa2a0b9ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E4=B8=89=E7=82=AE?= <15856818120@163.com> Date: Mon, 11 Aug 2025 16:00:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/bonus/autoweb/base/AutoMain.java | 44 +++++++++++++++---- .../com/bonus/autoweb/base/DutyLogIOp.java | 18 +++++++- 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/bonus/autoweb/base/AutoMain.java b/src/main/java/com/bonus/autoweb/base/AutoMain.java index b5199be..7662ee6 100644 --- a/src/main/java/com/bonus/autoweb/base/AutoMain.java +++ b/src/main/java/com/bonus/autoweb/base/AutoMain.java @@ -38,7 +38,7 @@ public class AutoMain { System.setProperty(DataConfig.DRIVE_NAME, DataConfig.drivePath); ChromeOptions option = new ChromeOptions(); //添加浏览器地址 - option.setBinary("C:\\Users\\Administrator\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe"); + option.setBinary("C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"); option.addArguments("--start-maximized"); option.addArguments("--force-device-scale-factor=0.75"); option.addArguments("disable-infobars"); @@ -132,9 +132,26 @@ public class AutoMain { //执行鼠标悬停动作-常态值班 - String ctzbXpath = "//*[@id=\"" + attributeId + "\"]/div/div[1]/div[2]/div[4]"; - WebElement wectzb = webDriver.findElement(By.xpath(ctzbXpath)); - action.moveToElement(wectzb).build().perform(); + //判断是否有相应的元素 + try { + Thread.sleep(2000); + //执行鼠标悬停动作-常态值班 + String ctzbXpath = "//*[@id=\"" + attributeId + "\"]/div/div[1]/div[2]/div[4]"; + WebElement wectzb = webDriver.findElement(By.xpath(ctzbXpath)); + action.moveToElement(wectzb).build().perform(); + } catch (Exception e) { + log.info("无确认框,在时间范围内----------"); + } + //判断是否有相应的元素 + try { + Thread.sleep(2000); + //执行鼠标悬停动作-常态值班 + String ctzbXpath = "//*[@id=\"" + attributeId + "\"]/div/div[1]/div/div[4]/div"; + WebElement wectzb = webDriver.findElement(By.xpath(ctzbXpath)); + action.moveToElement(wectzb).build().perform(); + } catch (Exception e) { + log.info("无确认框,在时间范围内----------"); + } Thread.sleep(300); @@ -191,10 +208,21 @@ public class AutoMain { Thread.sleep(300); //执行鼠标悬停动作-检查操练管理 - String ctzbXpath = "//*[@id=\"" + attributeId + "\"]/div/div[1]/div[2]/div[5]"; - webDriver.findElement(By.xpath(ctzbXpath)).click(); -// WebElement wectzb = -// action.moveToElement(wectzb).build().perform(); + try { + Thread.sleep(2000); + String ctzbXpath = "//*[@id=\"" + attributeId + "\"]/div/div[1]/div[2]/div[5]"; + webDriver.findElement(By.xpath(ctzbXpath)).click(); + } catch (Exception e) { + log.info("无确认框,在时间范围内----------"); + } + //判断是否有相应的元素 + try { + Thread.sleep(2000); + String ctzbXpath = "//*[@id=\"" + attributeId + "\"]/div/div/div/div[5]/div"; + webDriver.findElement(By.xpath(ctzbXpath)).click(); + } catch (Exception e) { + log.info("无确认框,在时间范围内----------"); + } Thread.sleep(1500); //打开检查计划页面 diff --git a/src/main/java/com/bonus/autoweb/base/DutyLogIOp.java b/src/main/java/com/bonus/autoweb/base/DutyLogIOp.java index e8c8dd1..c71fc1c 100644 --- a/src/main/java/com/bonus/autoweb/base/DutyLogIOp.java +++ b/src/main/java/com/bonus/autoweb/base/DutyLogIOp.java @@ -50,8 +50,22 @@ public class DutyLogIOp { // /html/body/div[2] 弹窗 您没有填写值班日志的排班班次 //定位写日志标签,打开日志页面 - webDriver.findElement(By.xpath("//*[@id=\"pane-5\"]/div/div[2]/div[2]/button")).click(); - log.info("定位写日志标签,打开日志页面----------"); + try { + //定位写日志标签,打开日志页面 + webDriver.findElement(By.xpath("//*[@id=\"pane-5\"]/div/div[2]/div[2]/button")).click(); + log.info("定位写日志标签,打开日志页面----------/div/div[2]/div[2]/button"); + Thread.sleep(1500); + } catch (Exception e) { + log.info("无确认框,在时间范围内----------/div/div[2]/div[2]/button"); + } + try { + //定位写日志标签,打开日志页面 + webDriver.findElement(By.xpath("//*[@id=\"pane-5\"]/div/div[2]/div[2]/button/span")).click(); + log.info("定位写日志标签,打开日志页面----------/div/div[2]/div[2]/button/span"); + Thread.sleep(1500); + } catch (Exception e) { + log.info("无确认框,在时间范围内----------/div/div[2]/div[2]/button/span"); + } Thread.sleep(300);