自动化测试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");
    }
}

运行结果如下:

相关推荐
祉猷并茂,雯华若锦11 小时前
Selenium与Playwright元素定位终极对决
selenium·测试工具
小白学大数据15 小时前
长周期爬虫的数据一致性:断点续爬 + 事务回滚保障采集质量
开发语言·爬虫·测试工具
小绫网络安全1 天前
Wireshark抓包完全入门教程:从零开始掌握网络分析
arm开发·测试工具·wireshark
梦想不只是梦与想2 天前
鸿蒙 测试工具:DevEco Testing(一)
测试工具·harmonyos·testing
ClouGence2 天前
Selenium 写不动了?这个工具录一次就能跑 Web 自动化
前端·selenium·测试
我的xiaodoujiao3 天前
快速学习Python基础知识详细图文教程17--类型注解和断点调试
开发语言·python·学习·测试工具
泽众云测试3 天前
泽众软件与日联科技达成合作,TestOne自动化测试平台助力搭建工业检测装备数字化品控防线
功能测试·测试工具·自动化
xy34533 天前
SQLMap 核心语法与使用指南(三)
测试工具·渗透测试·sqlmap
我的xiaodoujiao3 天前
快速学习Python基础知识详细图文教程18--多线程
开发语言·python·学习·测试工具