关于搭建idea+selenium+chrome

关于使用idea+selenium+chrome

准备
首先小伙伴得有idea这个工具,今天在搭建环境时看了很多教程,可能是基础不够,确实尽力了很多坑,下面来给大家分享一下最后怎么搭建成功的。

创建一个MAVEN项目
首先需要创建一个maven项目,打开idea,在创建项目之前先设置好,不然创建过程会非常的耗时间。

首先进入到设置页面
在这里插入图片描述

在VM Options内添加-DarchetypeCatalog=internal 运行参数
在这里插入图片描述

接着按照网上的教程创建一个maven项目即可

引入SELENIUM包
打开项目中的pom.xml文件,搜索selenium Java 选择需要用到的版本 此例用到3.4.0 选择3.4.0版本。默认出现Maven 需要用到的脚本,复制粘贴到pom.xml ,配置的最后一步完成!我自己用到的是4.1.4版本的

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.java.demo</groupId>
  <artifactId>demo</artifactId>
  <version>1.0-SNAPSHOT</version>

  <dependencies>

    <!-- selenium-java -->
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>4.1.4</version>
    </dependency>
  </dependencies>	
</project>

然后点击file -> Project Structure ->Modules,导入包即可。(包是在selenium官网下载https://www.seleniumhq.org/download/)
在这里插入图片描述

一个小DEMO
然后建一个java文件,写入下面代码,运行即可自动打开百度

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.io.File;

public class test {
    public static void main(String[] args) {

        File file = new File("C://driver/chromedriver.exe");
        System.setProperty("webdriver.chrome.driver",file.getAbsolutePath());
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.baidu.com/");

        String title = driver.getTitle();
        System.out.printf(title);

//         driver.close();
    }

}

链接:jar包下载 https://www.selenium.dev/downloads/.
转载于https://www.freesion.com/article/9258771702/
Error java 错误 不支持发行版本5 ( 完美解决版):https://blog.csdn.net/F_qiu/article/details/124102258

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值