From 3f545da5e84e03dd553048f4c178471da93c24ac Mon Sep 17 00:00:00 2001 From: jjLv <1981429112@qq.com> Date: Mon, 30 Sep 2024 15:05:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A9=E8=BE=9B=E8=87=AA=E5=8A=A8=E5=8C=96?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/bonus/autoweb/base/AutoMain.java | 75 ++++++++++++++++--- .../com/bonus/autoweb/base/AutoUtils.java | 3 - 2 files changed, 65 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/bonus/autoweb/base/AutoMain.java b/src/main/java/com/bonus/autoweb/base/AutoMain.java index 216bf26..d73abe4 100644 --- a/src/main/java/com/bonus/autoweb/base/AutoMain.java +++ b/src/main/java/com/bonus/autoweb/base/AutoMain.java @@ -1,6 +1,5 @@ package com.bonus.autoweb.base; -import lombok.Getter; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; @@ -23,31 +22,34 @@ import java.util.concurrent.TimeUnit; public class AutoMain { Logger log = LoggerFactory.getLogger(AutoMain.class); - /** - * A {@link WebDriver} instance used for browser automation and control. - * This object represents a browser window or tab, allowing interactions with web pages, - * navigation, form filling, and other browser-related tasks in a programmatic manner. - * - * @see Selenium WebDriver documentation - */ //浏览器驱动对象 - @Getter private WebDriver webDriver; + public WebDriver getWebDriver() { + return webDriver; + } + /** * 初始化驱动 */ public void initDrive(int type) { // chromedriver服务地址 - System.setProperty(DataConfig.DRIVE_NAME, DataConfig.DRIVE_PATH); + System.setProperty(DataConfig.DRIVE_NAME, DataConfig.drivePath); 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:\\Users\\19814\\AppData\\Local\\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("--force-device-scale-factor=0.75"); option.addArguments("disable-infobars"); //隐藏页面 +// option.addArguments("--headless"); +// webDriver = new FirefoxDriver(option); webDriver = new ChromeDriver(option); } @@ -136,6 +138,16 @@ public class AutoMain { */ private void openDuty() throws InterruptedException { Thread.sleep(5000); +// +// try { +// WebElement alertDiv = webDriver.findElement(By.xpath("/html/body/div[2]/div/div[1]/div/div[1]/div[1]/span")); +// if(alertDiv.getText()) { +// +// } +// }catch (Exception e){ +// +// } + try { webDriver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); } catch (Exception e) { @@ -198,7 +210,16 @@ public class AutoMain { log.info("管理标签的ID值为:" + attributeId); Thread.sleep(300); + +// //执行鼠标悬停动作-常态值班 +// String ctzbXpath = "//*[@id=\"" + attributeId + "\"]/div/div[1]/div[2]/div[3]"; +// WebElement wectzb = webDriver.findElement(By.xpath(ctzbXpath)); +// action.moveToElement(wectzb).build().perform(); +// Thread.sleep(300); + + //打开预警响应管理页面 + //*[@id=\"" + attributeId + "\"]/div/div[2]/div[2]/div[1]/div[2] String zbglXpath = "//*[@id=\"" + attributeId + "\"]/div/div/div[2]/div[3]"; webDriver.findElement(By.xpath(zbglXpath)).click(); log.info("打开预警页面------------"); @@ -228,7 +249,16 @@ public class AutoMain { log.info("管理标签的ID值为:" + attributeId); Thread.sleep(300); + +// //执行鼠标悬停动作-预警行动 +// String ctzbXpath = "//*[@id=\"" + attributeId + "\"]/div/div[1]/div[2]/div[4]"; +// WebElement wectzb = webDriver.findElement(By.xpath(ctzbXpath)); +// action.moveToElement(wectzb).build().perform(); +// Thread.sleep(300); + + //打开预警响应管理页面 + //*[@id=\"" + attributeId + "\"]/div/div[2]/div[2]/div[1]/div[2] String zbglXpath = "//*[@id=\"" + attributeId + "\"]/div/div/div[2]/div[4]"; webDriver.findElement(By.xpath(zbglXpath)).click(); log.info("打开预警页面------------"); @@ -265,15 +295,28 @@ public class AutoMain { //执行鼠标悬停动作-检查操练管理 String ctzbXpath = "//*[@id=\"" + attributeId + "\"]/div/div[1]/div[2]/div[5]"; webDriver.findElement(By.xpath(ctzbXpath)).click(); +// WebElement wectzb = +// action.moveToElement(wectzb).build().perform(); Thread.sleep(1500); //打开日常操练页面 + //*[@id=\"" + attributeId + "\"]/div/div[2]/div[2]/div[1]/div[2] +// String zbglXpath = "//*[@id=\"" + attributeId + "\"]/div/div[2]/div[2]/div/div[1]"; +// webDriver.findElement(By.xpath(zbglXpath)).click(); +// log.info("打开日常操练页面------------"); // /* TODO 800 --> 1500 */ +// Thread.sleep(1500); + //定位日常操练iframe的标签 WebElement dutyIframe = webDriver.findElement(By.id("rccl")); webDriver.switchTo().frame(dutyIframe); log.info("定位到日常操练iframe-----------"); Thread.sleep(8000); + //定位日常操练iframe的标签 +// WebElement insideIframe = webDriver.findElement(By.xpath("/html/body/div/section/div[1]/div[2]/div/iframe")); +// webDriver.switchTo().frame(insideIframe); +// log.info("定位到日常操练内部iframe-----------"); +// Thread.sleep(3000); } /** @@ -311,10 +354,17 @@ public class AutoMain { //执行鼠标悬停动作-检查操练管理 String ctzbXpath = "//*[@id=\"" + attributeId + "\"]/div/div[1]/div[2]/div[5]"; webDriver.findElement(By.xpath(ctzbXpath)).click(); +// WebElement wectzb = +// action.moveToElement(wectzb).build().perform(); Thread.sleep(1500); //打开检查计划页面 + //*[@id=\"" + attributeId + "\"]/div/div[2]/div[2]/div[1]/div[2] +// String zbglXpath = "//*[@id=\"" + attributeId + "\"]/div/div[2]/div[2]/div/div[1]"; +// webDriver.findElement(By.xpath(zbglXpath)).click(); +// log.info("打开日常操练页面------------"); // /* TODO 800 --> 1500 */ +// Thread.sleep(1500); //定位检查计划iframe的标签 WebElement dutyIframe = webDriver.findElement(By.id("rccl")); @@ -324,5 +374,10 @@ public class AutoMain { //点击抽查按钮 webDriver.findElement(By.xpath("/html/body/div/section/div[1]/div[1]/div/div/div/div[3]")).click(); +// //定位日常操练iframe的标签 +// WebElement insideIframe = webDriver.findElement(By.xpath("/html/body/div/section/div[1]/div[2]/div/iframe")); +// webDriver.switchTo().frame(insideIframe); +// log.info("定位到日常操练内部iframe-----------"); +// Thread.sleep(3000); } } diff --git a/src/main/java/com/bonus/autoweb/base/AutoUtils.java b/src/main/java/com/bonus/autoweb/base/AutoUtils.java index 081bc52..d7549bb 100644 --- a/src/main/java/com/bonus/autoweb/base/AutoUtils.java +++ b/src/main/java/com/bonus/autoweb/base/AutoUtils.java @@ -4,9 +4,6 @@ import java.io.*; -/** - * @author Lenovo - */ public class AutoUtils {