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

运行结果如下:

相关推荐
别来无恙1492 小时前
使用Python和Selenium进行Web自动化测试:从入门到实践
selenium·测试工具
Python大数据分析@2 小时前
python用selenium怎么规避检测?
开发语言·python·selenium·网络爬虫
ThreeAu.2 小时前
Miniconda3搭建Selenium的python虚拟环境全攻略
开发语言·python·selenium·minicoda·python环境配置
测试老哥14 小时前
6个步骤实现Postman接口压力测试
自动化测试·软件测试·测试工具·测试用例·接口测试·压力测试·postman
北岛三生1 天前
ISP(图像信号处理器)
图像处理·数码相机·测试工具·计算机视觉·测试用例·模块测试
北岛三生2 天前
Camera tuning flow相机调试流程
图像处理·数码相机·测试工具·模块测试
晋人在秦 老K2 天前
入梦工具箱怎么检测硬件?3步完成CPU-Z跑分测试 硬件检测总出错?图吧工具箱免费功能实测 draw.io 部署指南:私有化流程图服务搭建教程
测试工具·流程图·工具·draw.io
zhangzeyuaaa3 天前
Selenium 超时完全指南:pageLoadTimeout、implicitlyWait 和 scriptTimeout 的深度解析
selenium·测试工具
泛联新安3 天前
如何根据项目需求选择合适的软件测试工具?iUnit智能单元测试平台提供专业化解决方案
c++·测试工具·单元测试