自动化测试selenium环境搭建

Chrome 浏览器 + IDEA

1:查看Chrome浏览器版本:

2:下载驱动:Chrome 驱动
我的 Chrome 版本是 121(大版本)

找到对应的下载,Windows 的就下载 win32 那个。

没有自己版本的

点击 Stable 进去,找到对应版本,复制链接即可下载。

3:添加到 java 环境中来:

4:新建一个项目,在 pom.xml 添加依赖:

java 复制代码
    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>
    </dependencies>

代码复制进去,可能会报红,需要点击右边加载,等待下载刷新后就不会报红了。

5:编写测试代码:

java 复制代码
package org.example;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class Main {
    public static void main(String[] args) {
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--remote-allow-origins=*");
        WebDriver webDriver = new ChromeDriver(options);
        webDriver.get("https://www.baidu.com");
    }
}

运行结果如下:

相关推荐
我的xiaodoujiao17 小时前
API 接口自动化测试详细图文教程学习系列25--继续处理testCase中的数据
python·学习·测试工具·pytest
сокол18 小时前
【网安-研判-WireShark流量分析】网页、RAT、FTP、垃圾邮箱的流量过滤规则实战
网络·测试工具·wireshark
川石课堂软件测试19 小时前
UI自动化测试|XPath元素定位实践
功能测试·测试工具·jmeter·microsoft·ui·postman·harmonyos
IT界的老黄牛20 小时前
手机 Chrome 远程调试实战:adb + DevTools,localhost 就是你的测试服
chrome·测试工具·adb
сокол20 小时前
【网安-研判-WireShark流量分析】HTTPS流量解密
测试工具·https·wireshark
川石课堂软件测试20 小时前
UI自动化测试|CSS元素定位实践
css·测试工具·ui·fiddler·单元测试·appium·harmonyos
深蓝电商API1 天前
Playwright vs Puppeteer vs Selenium 2026终极对比
爬虫·selenium·puppeteer·playwright
可可南木2 天前
3070文件格式--21--fixture文件 3
功能测试·测试工具
一只小白0002 天前
【JVM | 第五篇】—— 深入理解垃圾回收
jvm·测试工具