Selenium学习

Selenium学习

Selenium简介

Selenium 是一系列工具和库的综合项目,这些工具和库支持 web 浏览器的自动化。

Selenium官网 < >
Selenium官方文档地址

Selenium安装配置

  1. 配置Selenium依赖 (Maven项目)

    <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
    </dependency>
    
  2. 安装浏览器 (可以参考 官方文档

    可以自行下载其他浏览器 或者使用系统自带的浏览器

  3. 安装WebDriver(浏览器驱动)

    当没有安装尝试启动项目时,会报以下异常:

    Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
    at com.google.common.base.Preconditions.checkState(Preconditions.java:847)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:134)
    at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:35)
    at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:159)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:94)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:123)
    at com.li.Test.main(Test.java:20)
    

    向右边拉动可以发现有链接http://chromedriver.storage.googleapis.com/index.html (以Chrome浏览器为例)

    下载自己浏览器对应版本,对应系统的zip文件并解压。

  4. 在程序中设置System Property

    /**
     * @param: webdriver.chrome.driver(可以查看上面的异常报错获取,如the xxx  system property中xxx及配置的系统变量名)
     * @param: D:\\driver\\chromedriver.exe 即为解压后的driver位置。
    */
    System.setProperty("webdriver.chrome.driver","D:\\driver\\chromedriver.exe");
    

Selenium使用

看官方文档—>To Selenium官方文档地址

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值