Selenium(一)1.环境搭建

Seleium官网:https://www.selenium.dev/

1.Pom.xml配置

创建Maven项目,添加Selenium依赖

<dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-java</artifactId>
  <version>4.4.0</version>
</dependency>

2.安装浏览器驱动

Setting up your system to allow a browser to be automated.
设置你的系统以允许浏览器自动化。

Through WebDriver, Selenium supports all major browsers on the market such as Chrome/Chromium, Firefox, Internet Explorer, Edge, and Safari. Where possible, WebDriver drives the browser using the browser’s built-in support for automation.
通过WebDriver,Selenium支持市场上所有主要浏览器,如Chrome/Chromium、Firefox、Internet Explorer、Edge和Safari。在可能的情况下,WebDriver使用浏览器的内置自动化支持驱动浏览器。

Since all the driver implementations except for Internet Explorer are provided by the browser vendors themselves, they are not included in the standard Selenium distribution. This section explains the basic requirements for getting started with the different browsers.
由于除Internet Explorer之外的所有驱动程序实现都是由浏览器供应商自己提供的,因此它们不包含在标准的Selenium发行版中。本节解释了开始使用不同浏览器的基本要求。

BrowserSupported OSMaintained byDownload
Chromium/ChromeWindows/macOS/LinuxGoogle下载链接
FirefoxWindows/macOS/LinuxMozilla下载链接
EdgeWindows/macOSMicrosoft下载链接
FirefoxWindows/macOS/LinuxMozilla下载链接

下载浏览器对应版本的驱动器即可

第一个自动化脚本

打开谷歌浏览器

	public class LuanchChrome {
    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver","C:\\Program Files\\chromedriver.exe");//后面放的是驱动器的路径

        //初始化一个谷歌浏览器实例 实例名称叫做driver
        WebDriver driver = new ChromeDriver();
    }
}

如图
如果你也可以打开浏览器,说明你已经成功的迈出了第一步~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值