Selenium实战 阅读次数: 安装依赖12345<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.141.59</version></dependency> 安装浏览器驱动下载安装 选择自己喜欢的浏览器,本文使用Edge 打开一个网页12345System.setProperty("webdriver.edge.driver", "D:\\edgedriver_win32\\MicrosoftWebDriver.exe"); //上面下载的浏览器驱动WebDriver driver = new EdgeDriver();driver.get("https://www.baidu.com/"); 定位元素1234567driver.findElement(By.id("kw")).sendKeys("java"); //输入内容driver.findElement(By.id("su")).click(); //点击按钮List<WebElement> muchoCheese = driver.findElements(By.cssSelector("#cheese li"));//获取多个与元素 获取页面cookie123456Set<Cookie> cookies = driver.manage().getCookies(); String cookieStr = ""; for (Cookie cookie : cookies) { cookieStr+= cookie.getValue(); } 浏览器加载扩展12345678File plugPath = new File("E:\\tsy\\tsy-tool.crx"); //创建options对象 ChromeOptions options = new ChromeOptions(); options.addExtensions(plugPath); WebDriver driver = new ChromeDriver(options); //这里使用的是chrome