package com.example.demo.controller; import com.alibaba.fastjson.JSONObject; import com.example.demo.base.Constants; import com.example.demo.domain.PatentCell; import com.example.demo.domain.UploadFileDTO; import com.example.demo.service.OutInterfaceService; import com.example.demo.service.UploadFromWebService; import com.example.demo.util.FileUtils; import com.example.demo.util.Response; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.quartz.SchedulerException; import org.springframework.context.annotation.Lazy; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; @Tag(name = "任务人员操作") @RestController @RequestMapping(Constants.QUARTZ_API + "/AssoTaskPersonel") @RequiredArgsConstructor(onConstructor_ = {@Lazy}) public class AssoTaskPersonelController { private final FileUtils fileUtils; private final UploadFromWebService uploadFromWebService; @GetMapping("/getStar") public List getPatentStar(String conditions,Integer id) throws Exception { return uploadFromWebService.getPatentStar(conditions,id); } @GetMapping("/format") public String format(String condition) throws InterruptedException, SchedulerException, IOException { return uploadFromWebService.formatConditions(condition); } @GetMapping("/getPartClient") @Operation(summary = "分页获取对比专利") public List getPatentya(String patentVO) throws IOException, InterruptedException { return uploadFromWebService.getPatentya(patentVO); } @GetMapping("/test") @Operation(summary = "分页获取对比专利") public void test(String patentVO) throws IOException, InterruptedException { System.setProperty("webdriver.chrome.driver", "D:\\driver\\chromedriver.exe"); // 1.创建webdriver驱动 WebDriver driver = new ChromeDriver(); //4、创建一个map集合存放浏览器句柄 HashMap handleMap = new HashMap<>(); //5、访问百度 driver.get("https://www.baidu.com/"); //6、获取到打开百度窗口的句柄 String baiDuHandle = driver.getWindowHandle(); //7、将百度句柄放到map中 handleMap.put("baidu", baiDuHandle); //8、新开一个窗口,用js来完成 String js = "window.open('https://www.sogou.com');"; ((JavascriptExecutor) driver).executeScript(js); //9、获取到所有的句柄 Set set = driver.getWindowHandles(); //10、循环找到搜狗窗口句柄 for (String s : set) { //10.1、将搜狗的句柄放到map中 if (!s.equals("baiDuHandle")) handleMap.put("souGou", s); } //11、切换到搜狗的窗口 driver.switchTo().window(handleMap.get("souGou")); driver.switchTo().window(handleMap.get("baidu")); driver.close(); } }