Commit c8184bc2 authored by ShangLiPeng's avatar ShangLiPeng

modify rpa

parent 974120dc
......@@ -69,7 +69,7 @@ public class LoginFunction extends BaseFunction {
return;
}
try {
rpa().waitElement(By.cssSelector("input.el-input__inner[placeholder=\"请设置密码\"]"), WAIT_TIME);
rpa().waitElementLoadAndVisible(By.cssSelector("input.el-input__inner[placeholder=\"请设置密码\"]"), WAIT_TIME);
rpa().refresh();
} catch (NoSuchElementException ignore) {
}
......@@ -194,7 +194,7 @@ public class LoginFunction extends BaseFunction {
protected void tryLogout() {
// 2. 尝试进行退出操作
try {
rpa().waitElement(By.cssSelector("div.user span.userName span.userNameInfo"), WAIT_TIME);
rpa().waitElementLoadAndVisible(By.cssSelector("div.user span.userName span.userNameInfo"), WAIT_TIME);
// 通过脚本进行退出操作
rpa().newHar();
rpa().executeJavaScript("""
......
......@@ -29,7 +29,7 @@ public class SessionFunction extends BaseFunction {
rpa().refresh();
rpa().sleep(SLEEP_TIME);
}
rpa().waitElement(By.cssSelector("div.user span.userName span.userNameInfo"), WAIT_TIME);
rpa().waitElementLoadAndVisible(By.cssSelector("div.user span.userName span.userNameInfo"), WAIT_TIME);
var val = rpa().executeJavaScript("""
return (function() {
try {
......
......@@ -101,7 +101,7 @@ public class SwitchTaxpayerFunction extends BaseFunction {
}
}
// 8. 等待返回电子税务局首页
rpa().waitElement(By.cssSelector("div.user span.userName span.userNameInfo"), WAIT_TIME);
rpa().waitElementLoadAndVisible(By.cssSelector("div.user span.userName span.userNameInfo"), WAIT_TIME);
// 8.1 补充……因为电子税务局的 bug,需要清理电子税务局内部网上办税子系统的 Cookies
try {
rpa().removeCookies("WSBSSESSION");
......
......@@ -7,6 +7,7 @@ import org.apache.commons.lang3.StringUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.net.Socket;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Date;
......@@ -16,9 +17,33 @@ public class ChromeKits {
public static void killBrowser(){
ProcessKits.killProcess(Arrays.asList( "firefox","geckodriver","crashreporter","chromedriver","chrome"));
}
public static boolean chromeIsRunning(){
Socket socket =null;
try{
socket = new Socket("127.0.0.1", 9222);
return true;
}
catch (Exception ex){
return false;
}
finally {
try{
socket.close();
}
catch (Exception ex){
}
}
}
//创建浏览器
public static String utilBrowserStart(String cmd)
{
if (chromeIsRunning()==true){
return "";
}
Runtime rt = Runtime.getRuntime();
try
{
......
......@@ -16,10 +16,8 @@ import net.lightbody.bmp.client.ClientUtil;
import net.lightbody.bmp.core.har.Har;
import net.lightbody.bmp.proxy.CaptureType;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.*;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
......@@ -35,10 +33,11 @@ import java.text.MessageFormat;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.BooleanSupplier;
import java.util.function.Supplier;
/**
......@@ -277,7 +276,7 @@ public class RpaCore {
*/
public Har newHar() {
//Mobo模式开启
if (this.config.isNetworkProxy()==false) {
if (this.config.isNetworkProxy() == false) {
if (!this.config.getRpa().getProxy().isEnable()) {
throw new IllegalStateException("当前 Robot 对象没有开启网络代理!");
}
......@@ -295,11 +294,10 @@ public class RpaCore {
* 结束当前网络监听集合
*/
public void stopHar() {
if (this.config.isNetworkProxy()==false) {
if (this.config.isNetworkProxy() == false) {
this.proxy.waitForQuiescence(QUIT_PERIOD, QUIT_PERIOD, TimeUnit.SECONDS);
return;
}
else {
} else {
this.closeNetWork();
}
}
......@@ -323,7 +321,7 @@ public class RpaCore {
*/
public String listen(String uri, long timeout) {
//Mobo模式的network
if (this.config.isNetworkProxy()==false) {
if (this.config.isNetworkProxy() == false) {
final var outTime = System.currentTimeMillis() + timeout * 1000;
try {
while (true) {
......@@ -346,8 +344,8 @@ public class RpaCore {
}
}
//chrome的network
else{
return this.listenNetWorkCenter(uri,timeout*1000L);
else {
return this.listenNetWorkCenter(uri, timeout * 1000L);
}
}
......@@ -474,40 +472,8 @@ public class RpaCore {
/**
* 默认元素等待时间 (60 秒)
*/
private static final long DEFAULT_WAIT_TIME = 60;
private static final long DEFAULT_WAIT_TIME = 10;
/**
* 判断元素是否可以点击
*
* @param element 要判断的元素
* @return 点击状态
*/
private boolean canClick(WebElement element) {
try {
var wait = new WebDriverWait(this.driver, Duration.of(5, TimeUnit.SECONDS.toChronoUnit()));
wait.until(ExpectedConditions.elementToBeClickable(element));
return true;
} catch (Exception ignored) {
}
return false;
}
/**
* 等待元素加载并可见
*
* @param by 查询元素
* @param waitTime 等待时间(单位:秒)
*/
public void waitElement(By by, long waitTime) {
try {
var wait = new WebDriverWait(this.driver, Duration.of(waitTime, TimeUnit.SECONDS.toChronoUnit()));
wait.until(ExpectedConditions.presenceOfElementLocated(by));
wait.until(ExpectedConditions.visibilityOfElementLocated(by));
} catch (Exception ex) {
// 如果等待元素超时,改为抛出元素不存在异常
throw new NoSuchElementException(by.toString());
}
}
/**
* 查找元素
......@@ -529,7 +495,7 @@ public class RpaCore {
* @throws NoSuchElementException,元素不存在或可用超时抛出
*/
public WebElement findElement(By by, long waitTime) {
this.waitElement(by, waitTime);
this.waitElementLoadAndVisible(by, waitTime);
return this.driver.findElement(by);
}
......@@ -566,7 +532,7 @@ public class RpaCore {
* @throws NoSuchElementException,元素不存在或可用超时抛出
*/
public List<WebElement> findElements(By by, long waitTime) {
this.waitElement(by, waitTime);
this.waitElementLoadAndVisible(by, waitTime);
return this.driver.findElements(by);
}
......@@ -608,7 +574,6 @@ public class RpaCore {
return this.findElementWithInnerText(innerText, this.findElements(element, by));
}
/**
* 在元素列表中查找内部文本符合条件的元素
*
......@@ -627,6 +592,312 @@ public class RpaCore {
}
throw new NoSuchElementException("inner text: " + innerText);
}
//==============findElementsLoad begin=====================
/**
* @param parentElement 父元素
* @param childBy 在父元素的范围内查找子元素
* @param waitTime
* @return
*/
public List<WebElement> findElementsLoadRoot(WebElement parentElement, By childBy, long waitTime, String throwEx) {
try {
//忽略可见
var wait = new WebDriverWait(this.driver, Duration.of(waitTime, TimeUnit.SECONDS.toChronoUnit()));
wait.until(ExpectedConditions.presenceOfNestedElementLocatedBy(parentElement, childBy));
return parentElement.findElements(childBy);
} catch (Exception e) {
if (StringUtils.isNotBlank(throwEx)) {
throw new NoSuchElementException(throwEx+":"+e.getMessage());
}
}
return null;
}
public List<WebElement> findElementsLoad(WebElement parentElement, By childBy, String throwEx) {
//忽略可见
return this.findElementsLoadRoot(parentElement, childBy, DEFAULT_WAIT_TIME, throwEx);
}
public List<WebElement> findElementsLoadRoot(By by, long waitTime, String throwEx) {
try {
//忽略可见
this.waitElementLoad(by, waitTime, throwEx);
return this.driver.findElements(by);
} catch (Exception e) {
if (StringUtils.isNotBlank(throwEx)) {
throw new NoSuchElementException(throwEx+":"+e.getMessage());
}
}
return null;
}
/**
* @param by
* @return
*/
public List<WebElement> findElementsLoad(By by, String throwEx) {
return findElementsLoadRoot(by, DEFAULT_WAIT_TIME, throwEx);
}
//==============findElementsLoad end=====================
//==================findElementAndIgnoreVisible begin=====================
public WebElement findElementLoadRoot(By by, long waitTime, String throwEx) {
try {
//忽略可见
this.waitElementLoad(by, waitTime, throwEx);
return this.driver.findElement(by);
} catch (Exception e) {
if (StringUtils.isNotBlank(throwEx)) {
throw new NoSuchElementException(throwEx+":"+e.getMessage());
}
}
return null;
}
public WebElement findElementLoadRoot(WebElement parentElement, By childBy, long waitTime, String throwEx) {
try {
//忽略可见
var wait = new WebDriverWait(this.driver, Duration.of(waitTime, TimeUnit.SECONDS.toChronoUnit()));
wait.until(ExpectedConditions.presenceOfNestedElementLocatedBy(parentElement, childBy));
return parentElement.findElement(childBy);
} catch (Exception e) {
if (StringUtils.isNotBlank(throwEx)) {
throw new NoSuchElementException(throwEx+":"+e.getMessage());
}
}
return null;
}
public WebElement findElementLoad(WebElement parentElement, By childBy, String throwEx) {
return findElementLoadRoot(parentElement, childBy, DEFAULT_WAIT_TIME, throwEx);
}
//==================findElementAndIgnoreVisible end=====================
//===============================waitElement begin===========================
/**
* 判断元素是否可以点击
*
* @param element 要判断的元素
* @return 点击状态
*/
public boolean waitElementCanClick(WebElement element) {
try {
var wait = new WebDriverWait(this.driver, Duration.of(5, TimeUnit.SECONDS.toChronoUnit()));
wait.until(ExpectedConditions.elementToBeClickable(element));
return true;
} catch (Exception ignored) {
System.out.println(ignored.getMessage());
}
return false;
}
/**
* 等待元素加载并可见
*
* @param by 查询元素
* @param waitTime 等待时间(单位:秒)
*/
public void waitElementLoadAndVisible(By by, long waitTime) {
try {
var wait = new WebDriverWait(this.driver, Duration.of(waitTime, TimeUnit.SECONDS.toChronoUnit()));
wait.until(ExpectedConditions.presenceOfElementLocated(by));
wait.until(ExpectedConditions.visibilityOfElementLocated(by));
} catch (Exception ex) {
// 如果等待元素超时,改为抛出元素不存在异常
throw new NoSuchElementException(by.toString());
}
}
/**
* 等待元素是否被加载
*
* @param by
* @param waitTime
*/
public boolean waitElementLoad(By by, long waitTime, String throwEx) {
try {
var wait = new WebDriverWait(this.driver, Duration.of(waitTime, TimeUnit.SECONDS.toChronoUnit()));
wait.until(ExpectedConditions.presenceOfElementLocated(by));
return true;
} catch (Exception ex) {
// 如果等待元素超时,改为抛出元素不存在异常
if (StringUtils.isNotBlank(throwEx)) {
throw new NoSuchElementException(throwEx+":"+by.toString());
}
}
return false;
}
public WebElement waitElementLoad(Supplier<WebElement> function, long timeout, String throwEx) {
Date start = new Date();
while (true) {
WebElement webElement = function.get();
if (webElement != null) {
return webElement;
}
this.sleep(10);
if (System.currentTimeMillis() - start.getTime() > timeout) {
if (StringUtils.isNotBlank(throwEx)) {
throw new NoSuchElementException(throwEx+":"+"waitElementLoad timeout");
}
return null;
}
}
}
/**
* @param waitTime
*/
public boolean waitElementVisible(WebElement element, long waitTime, String throwEx) {
try {
var wait = new WebDriverWait(this.driver, Duration.of(waitTime, TimeUnit.SECONDS.toChronoUnit()));
wait.until(ExpectedConditions.visibilityOf(element));
return true;
} catch (Exception ex) {
// 如果等待元素超时,改为抛出元素不存在异常
if (StringUtils.isNotBlank(throwEx)) {
throw new NoSuchElementException(throwEx+":"+ex.getMessage());
}
}
return false;
}
//===============================waitElement end===========================
//====================clickAndExcept begin=========================
/**
* 点某个元素之后期望exceptFunction返回true
*
* @param clickElement
* @param exceptFunction 期望的匿名函数
* @param exceptFunctionTimeout 表达式超时时间
*/
public boolean clickAndExceptRoot(WebElement clickElement, BooleanSupplier exceptFunction, Long exceptFunctionTimeout, String throwEx) {
//点击
this.click(clickElement);
//等待期望元素出现
Date start = new Date();
while (true) {
boolean asBoolean = exceptFunction.getAsBoolean();
if (Objects.equals(asBoolean, true)) {
return true;
}
if (Objects.equals(asBoolean, false)) {
continue;
}
if (System.currentTimeMillis() - start.getTime() > exceptFunctionTimeout) {
if (StringUtils.isNotBlank(throwEx)) {
throw new NoSuchElementException(throwEx+":"+"clickAndExceptRoot timeout");
}
return false;
}
this.sleep(10);
}
}
//====================clickAndExcept end=========================
public boolean clickAndExcept(By clickBy, BooleanSupplier exceptFunction, String throwEx) {
WebElement clickElement = this.findElementLoadRoot(clickBy, DEFAULT_WAIT_TIME, throwEx);
return this.clickAndExceptRoot(clickElement, exceptFunction, DEFAULT_WAIT_TIME, throwEx);
}
public boolean clickAndExcept(WebElement clickElement, BooleanSupplier exceptFunction, String throwEx) {
return this.clickAndExceptRoot(clickElement, exceptFunction, DEFAULT_WAIT_TIME, throwEx);
}
//========================clickByFunc begin==========================
/**
* 通过function进行点击元素
*
* @param function 如何点击元素的行为的匿名函数
* @param timeout
* @return
*/
public boolean clickByFuncRoot(Supplier<WebElement> function, long timeout, String throwEx) {
try {
WebElement webElement = this.waitElementLoad(function, timeout, throwEx);
this.click(webElement);
return true;
} catch (Exception e) {
if (StringUtils.isNotBlank(throwEx)) {
throw new NoSuchElementException(throwEx+":"+e.getMessage());
}
return false;
}
}
public boolean clickByFunc(Supplier<WebElement> function, String throwEx) {
return this.clickByFuncRoot(function, DEFAULT_WAIT_TIME, throwEx);
}
/**
* 通过function进行点击元素 之后 期望 exceptFunction为true
*
* @param function 如何点击元素的行为的匿名函数
* @param timeout
* @param exceptFunction 点击之后的结果
* @param exceptFunctionTimeout
* @return
*/
public boolean clickByFunc(Supplier<WebElement> function, long timeout, BooleanSupplier exceptFunction, Long exceptFunctionTimeout, String throwEx) {
try {
//点击
this.clickByFuncRoot(function, timeout, throwEx);
//等待期望结果出现
Date start = new Date();
while (true) {
boolean asBoolean = exceptFunction.getAsBoolean();
//期望结果出现
if (Objects.equals(asBoolean, true)) {
return true;
}
if (Objects.equals(asBoolean, false)) {
continue;
}
//期望结果超时
if (System.currentTimeMillis() - start.getTime() > exceptFunctionTimeout) {
throw new NoSuchElementException(throwEx+":"+"clickByFunc timeout");
}
this.sleep(10);
}
}
catch (Exception e) {
if (StringUtils.isNotBlank(throwEx)) {
throw new NoSuchElementException(throwEx+":"+e.getMessage());
}
return false;
}
}
public boolean clickByFunc(Supplier<WebElement> function, BooleanSupplier exceptFunction, String throwEx) {
return this.clickByFunc(function, DEFAULT_WAIT_TIME, exceptFunction, DEFAULT_WAIT_TIME, throwEx);
}
//========================clickByFunc end==========================
public boolean jsClick(WebElement element) {
try {
this.executeJavaScript("arguements[0].click()", Object.class, element);
return true;
} catch (Exception e) {
return false;
}
}
/* ------------------------- 页面元素交互 ------------------------- */
/**
......@@ -714,13 +985,36 @@ public class RpaCore {
return;
}
this.scrollTo(element);
if (!this.config.getRpa().isSimulate() && this.canClick(element)) {
this.addBorder(element);
this.sleep(2000);
if (!this.config.getRpa().isSimulate() && this.waitElementCanClick(element)) {
element.click();
} else {
this.moveTo(element);
WinApi.leftClick();
}
}
this.clearBorder(element);
}
//public void clickWhile(WebElement element) {
// if (Objects.isNull(element)) {
// return;
// }
// Date start = new Date();
// while (true) {
// this.scrollTo(element);
// this.sleep(100);
// this.addBorder(element);
// if (this.waitElementVisible(element, 2L)) {
// element.click();
// break;
// }
// if (System.currentTimeMillis() - start.getTime() > 2000) {
// this.jsClick(element);
// }
// }
// this.clearBorder(element);
//}
/**
* 向指定元素输出文本
......@@ -924,6 +1218,7 @@ public class RpaCore {
/**
* 使用selenium方式拖拽元素一定的偏移距离
*
* @param dragHandler
* @param xoffset
*/
......@@ -946,10 +1241,10 @@ public class RpaCore {
action.release().build().perform();
}
public void drag(WebElement dragHandler, WebElement dragHandlerContiner){
public void drag(WebElement dragHandler, WebElement dragHandlerContiner) {
// Rectangle handlerRect = this.sumElementRectangle(dragHandlerContiner);
int xoffset=dragHandlerContiner.getRect().width;
this.dragCenter(dragHandler,xoffset);
int xoffset = dragHandlerContiner.getRect().width;
this.dragCenter(dragHandler, xoffset);
}
/* ------------------------- 辅助方法 ------------------------- */
......@@ -1091,8 +1386,7 @@ public class RpaCore {
devTools.addListener(Network.responseReceived(), res -> {
try {
networkMap.put(res.getResponse().getUrl(), devTools.send(Network.getResponseBody(res.getRequestId())).getBody());
}
catch (Exception ex){
} catch (Exception ex) {
}
});
......@@ -1188,5 +1482,29 @@ public class RpaCore {
public void resetInputState() {
this.driver.resetInputState();
}
public void addBorder(WebElement element) {
try {
this.addAttribute(element, "style", "border:1px solid red");
} catch (Exception e) {
e.printStackTrace();
}
}
public void clearBorder(WebElement element) {
try {
this.addAttribute(element, "style", "border:0px solid red");
} catch (Exception e) {
e.printStackTrace();
}
}
public void addAttribute(WebElement element, String attributeName, String atributeValue) {
if (element == null) {
return;
}
String script = MessageFormat.format("arguments[0].setAttribute(''{0}'', ''{1}'')", attributeName, atributeValue);
this.executeJavaScript(script, Object.class, element);
}
}
......@@ -21,13 +21,19 @@ useSeleniumDrag: true
networkProxy: true
#是否使用selenium来自动启动浏览器
remoteDebugging: false
remoteDebugging: true
remoteDebuggingPort: 9222
remoteDebuggingIP: "127.0.0.1"
# cmd.exe /c cmd 是执行完cmd命令后关闭命令窗口;
# cmd.exe /k cmd 是执行完cmd命令后不关闭命令窗口;
# cmd.exe /c start cmd 会打开一个新窗口后执行cmd指令,原窗口会关闭;
# cmd.exe /k start cmd 会打开一个新窗口后执行cmd指令,原窗口不会关闭;
# cmd.exe /k start /b cmd 会打开一个隐藏的窗口执行cmd指令,原窗口不会关闭
# cmd /b /Google/Chrome/Application/chrome.exe --remote-debugging-port=9222 --user-data-dir=/selenium/ChromeProfile --allow-pre-commit-input --disable-background-networking --disable-backgrounding-occluded-windows --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-infobars --disable-popup-blocking --disable-prompt-on-repost --disable-sync --enable-blink-features=ShadowDOMV0 --enable-logging --ignore-certificate-errors --log-level=3 --no-service-autorun --password-store=basic --start-maximized --test-type --use-mock-keychain --flag-switches-begin --flag-switches-end
#remoteDebuggingCmd: "/Google/Chrome/Application/chrome.exe --remote-debugging-port=9222 --user-data-dir=/selenium/ChromeProfile --allow-pre-commit-input --disable-background-networking --disable-backgrounding-occluded-windows --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-infobars --disable-popup-blocking --disable-prompt-on-repost --disable-sync --enable-blink-features=ShadowDOMV0 --enable-logging --ignore-certificate-errors --log-level=3 --no-service-autorun --password-store=basic --start-maximized --test-type --use-mock-keychain --flag-switches-begin --flag-switches-end"
#remoteDebuggingCmd: "cmd.exe /c start /b C:\\Google\\Chrome\\Application\\chrome.bat"
remoteDebuggingCmd: "cmd.exe /c start /b C:\\Google\\Chrome\\Application\\chrome.bat"
remoteDebuggingCmd: "cmd.exe /c start /b D:\\Google\\Chrome\\Application\\chrome.bat"
......
import cn.hutool.core.collection.CollectionUtil;
import com.greatchn.rpa.RpaCore;
import com.greatchn.rpa.config.RpaConfig;
import com.greatchn.yzh.TaskExecutor;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
public class DriverTest {
public static void main(String[] args) throws InterruptedException {
var config = RpaConfig.build();
RpaCore rpa=new RpaCore(config);
rpa.visit("chrome://version/");
RpaCore rpa = new RpaCore(config);
//rpa.visit("chrome://version/");
//network
//rpa.enableNetWork();
rpa.visit("https://www.baidu.com");
System.out.println(rpa.listenNetWorkCenter("sugrec", 10000L));
//rpa.visit("https://www.baidu.com");
//System.out.println(rpa.listenNetWorkCenter("sugrec", 10000L));
//drag
rpa.visit("https://tpass.tianjin.chinatax.gov.cn:8443/#/login?redirect_uri=https%3A%2F%2Fetax.tianjin.chinatax.gov.cn%2Foutsider%2Fsso%2FmainPage.do&client_id=x3ef652ax3294xz6beefnf5zadbf66cc&response_type=code&state=test");
var dragHandler = rpa.findElement(By.cssSelector(".handler.animate"), 1);
//rpa.visit("https://tpass.tianjin.chinatax.gov.cn:8443/#/login?redirect_uri=https%3A%2F%2Fetax.tianjin.chinatax.gov.cn%2Foutsider%2Fsso%2FmainPage.do&client_id=x3ef652ax3294xz6beefnf5zadbf66cc&response_type=code&state=test");
//var dragHandler = rpa.findElement(By.cssSelector(".handler.animate"), 1);
//
//WebElement continer=rpa.findElement(dragHandler,By.xpath("./.."));
//System.out.println(continer.getText());
//rpa.drag(dragHandler,continer);
djKprq(rpa, 0, "2020", "6", "1");
djKprq(rpa, 1, "2021", "2", "15");
}
public static void djKprq(RpaCore rpa, Integer type, String year, String month, String day) {
//点击的日期面板(点击年,月,日等控件的父元素)
String parentPath = ".//div[@class='t-popup t-date-picker__panel-container'][@data-popper-placement]";
//点击年下拉框
String header_controller_year = ".//div[@class='t-select__wrap t-date-picker__header-controller-year']//input";
//点击年份的xpath
String click_year_xpath = String.format(".//div[@class='t-popup t-select__dropdown t-date-picker__header-controller-year-popup']//ul/li//span[text()='%s']", year);
//点击月下拉框
String header_controller_month =".//div[@class='t-select__wrap t-date-picker__header-controller-month']//input";
//点击确定的月
String click_month_xpath = String.format(".//div[@class='t-popup t-select__dropdown t-date-picker__header-controller-month-popup']//ul/li//span[text()='%s 月']", month);
//点击确定的日
String click_day_xpath = String.format(".//div[@class='t-date-picker__table']//div[@class='t-date-picker__cell-inner'][text()=%s]", day);
List<WebElement> parent = new ArrayList<>();
if (Objects.equals(0, type)) {
//点击开票日期 起
rpa.clickAndExcept(By.cssSelector("input[placeholder='开票日期起']"), () -> {
List<WebElement> tmpList = rpa.findElementsLoad(By.xpath(parentPath),"未找到开票日期起");
if (CollectionUtil.isEmpty(tmpList)) {
return false;
}
parent.add(tmpList.get(0));
return true;
},"未找到开票日期起");
} else {
//点击开票日期 止
rpa.clickAndExcept(By.cssSelector("input[placeholder='开票日期止']"), () -> {
List<WebElement> tmpList = rpa.findElementsLoad(By.xpath(parentPath),"未找到开票日期止");
if (CollectionUtil.isEmpty(tmpList)) {
return false;
}
parent.add(tmpList.get(0));
return true;
},"未找到开票日期止");
}
System.out.println("点击年下拉框");
//点击年下拉框
rpa.clickByFunc(() -> {
WebElement yearDropDownList = rpa.findElementLoad(parent.get(0), By.xpath(header_controller_year),"点击年下拉框失败");
return yearDropDownList;
},"点击年下拉框失败");
//rpa.sleep(10000);
System.out.println("点击确定的年");
//点击确定的年
rpa.clickByFunc(() -> {
WebElement clickYear = rpa.findElementLoad(parent.get(0), By.xpath(click_year_xpath),"点击确定的年失败");
return clickYear;
},"点击确定的年失败");
//rpa.sleep(1000);
//点击月下拉框
rpa.clickByFunc(() -> {
WebElement monthDropDownList = rpa.findElementLoad(parent.get(0), By.xpath(header_controller_month),"点击月下拉框失败");
return monthDropDownList;
},"点击月下拉框失败");
//rpa.sleep(1000);
//点击确定的月
rpa.clickByFunc(() -> {
WebElement clickMonth = rpa.findElementLoad(parent.get(0), By.xpath(click_month_xpath),"点击确定的月失败");
return clickMonth;
},"点击确定的月失败");
//rpa.sleep(1000);
WebElement continer=rpa.findElement(dragHandler,By.xpath("./.."));
System.out.println(continer.getText());
rpa.drag(dragHandler,continer);
//点击日
rpa.clickByFunc(() -> {
WebElement clickDay = rpa.findElementLoad(parent.get(0), By.xpath(click_day_xpath),"点击日失败");
return clickDay;
},"点击日失败");
//rpa.sleep(1000);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment