Java安装Selenium⾃动化 Java如何安装前提Selenium⾃动化java版本最低要求为8电脑⾄少已安装⼀种浏览器如Chrome推荐、Edge、Firefox、IE、Safari提⽰浏览器必须为官⽹下载的正版浏览器根据以往经验存在部分同学电脑安装的浏览器为盗版导致⽆法执⾏⾃动化1.打开intellij idea创建Maven项⽬2. 添加依赖dependency groupIdio.github.bonigarcia/groupId artifactIdwebdrivermanager/artifactId version5.8.0/version /dependency dependency groupIdorg.seleniumhq.selenium/groupId artifactIdselenium-java/artifactId version4.29.0/version /dependency3.在test路径下创建自动化文件3.1项目结构3.2代码firstTest.javaimport io.github.bonigarcia.wdm.WebDriverManager; import org.openqa.selenium.By; 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.support.ui.WebDriverWait; import org.openqa.selenium.support.ui.ExpectedConditions; import java.time.Duration; import java.util.List; public class firstTest { void searchTest() throws InterruptedException { // 驱动程序管理的自动化 WebDriverManager.chromedriver().setup(); ChromeOptions options new ChromeOptions(); //这个是我的谷歌浏览器的路径 options.setBinary(E:\\Chrome\\Application\\chrome.exe); // 允许访问所有链接 options.addArguments(--remote-allow-origins*); //1.打开浏览器 WebDriver driver new ChromeDriver(options); //2.输入百度链接 driver.get(https://www.baidu.com); //****************** xpath 定位 ******* /*3、找到输入框并输入 driver.findElement (By.xpath(//*[id\chat-textarea\])).sendKeys (csdn); Thread.sleep(3000); //4、找到“百度一下”按钮并点击 driver.findElement(By.xpath(//*[id\chat-submit-button\])).click();*/ //************************************************************************* //****************** cssSelector 定位*********************** //3、找到输入框并输入 //driver.findElement (By.cssSelector(#chat-textarea)).sendKeys (csdn); //Thread.sleep(3000); //4、找到“百度一下”按钮并点击 //driver.findElement(By.cssSelector(#chat-submit-button)).click(); //************************************************************************* //5、关闭浏览器 driver.quit(); } }xpath 定位 和 cssSelector 定位选择一个即可方法不一样结果是一样的runTest.javapublic class runTest { public static void main(String[] args) throws InterruptedException { firstTest test new firstTest(); test.searchTest(); } }4.运⾏⾃动化点击运⾏程序将⾃动实现百度搜索全过程。5. 具体细节请看下集https://blog.csdn.net/2302_77623737/article/details/163372094?spm1001.2014.3001.5502

相关新闻

最新新闻

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现

SerenityOS 命令行选项解析指南:getopt 与 getopt_long 用法、返回值与底层实现 【免费下载链接】serenity The Serenity Operating System 🐞 项目地址: https://gitcode.com/GitHub_Trending/se/serenity 导读 本文以 getopt(3) 手册 为核心&a…

2026/9/29 2:52:50
轻量服务器还是ECS?大促云服务器选购与避坑实战指南

轻量服务器还是ECS?大促云服务器选购与避坑实战指南

每年大促节点,群里永远有人在问同一个问题:“38元的轻量服务器到底怎么抢?为什么我每次点进去都是已售罄?68元直购和99元的ECS我到底选哪个?”作为一个常年帮团队和自己采购云服务器的老用户,我太清楚这种纠…

2026/9/29 2:52:51
为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南

为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南

为 AI 代理的 Review 动作编写 Cedar 审批门控策略:review-agent-governance 策略编写实战指南 【免费下载链接】agents Multi-harness agentic plugin marketplace for Claude Code, Codex, Cursor, OpenCode, GitHub Copilot, and Google Antigravity 项目地址:…

2026/9/29 1:29:30
PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署

PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署

PaddleOCR 手写数学公式识别算法 CAN 实战指南:Counting-Aware Network 训练、评估与推理部署 【免费下载链接】PaddleOCR Turn any PDF or image document into structured data for your AI. A powerful, lightweight OCR toolkit that bridges the gap between i…

2026/9/29 1:39:24
Spring源码解析:构造器注入的类型转换与候选匹配机制

Spring源码解析:构造器注入的类型转换与候选匹配机制

/* MD / 富文本中的 .toc(含博客园搬家等嵌套结构);.toc-box 在侧栏,不受影响 */#content_views .toc,/* 编辑器常在目录前后插入空 p(:empty 仍占 20px),一并去掉避免顶空隙 */#content_views.markdown_views > p:empty:has(+ .toc),#content_views.markdown_views …

2026/9/29 22:57:57
openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由

openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由

openai-agents-python 多模型接入指南:深入解析 AnyLLMModel 适配层与 any-llm 路由 【免费下载链接】openai-agents-python A lightweight, powerful framework for multi-agent workflows 项目地址: https://gitcode.com/GitHub_Trending/op/openai-agents-pyth…

2026/9/29 2:52:53

日新闻

周新闻