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
{
......
This diff is collapsed.
......@@ -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