首页 > 编程语言 >搭建web自动化环境,selenium-Java+火狐浏览器+idea

搭建web自动化环境,selenium-Java+火狐浏览器+idea

时间:2022-12-31 16:57:41浏览次数:32  
标签:webDriver 插件 浏览器 web selenium 火狐 Java com

1、准备浏览器,火狐/谷歌等

2、下载驱动插件

火狐插件链接:https://github.com/mozilla/geckodriver/releases

谷歌插件:https://registry.npmmirror.com/binary.html?path=chromedriver/

                 https://chromedriver.storage.googleapis.com/index.html

注意与浏览器版本对应关系

3、打开idea,创建项目,添加依赖,并测试程序

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

编写程序进行测试

public class WebDriverTest {

    public static void main(String[] args) throws InterruptedException {
        // 加载驱动
        System.setProperty("webdriver.gecko.driver","E:\\BaiduNetdiskDownload\\geckodriver.exe");
        // 指明浏览器位置,否则会报【Caused by: org.openqa.selenium.WebDriverException: Driver server process died prematurely.】
        System.setProperty("webdriver.firefox.bin","C:\\Program Files\\Mozilla Firefox\\firefox.exe");
        WebDriver webDriver = new FirefoxDriver() ;
        // 打开百度
        webDriver.get("http://www.baidu.com/");
        // 在搜索框输入内容
        webDriver.findElement(By.id("kw")).sendKeys("这里输入搜索内容");
        //  停留2S
        Thread.sleep(2000);
        //关闭驱动,以及所有相关窗口
        webDriver.quit();
    }
}

 

标签:webDriver,插件,浏览器,web,selenium,火狐,Java,com
From: https://www.cnblogs.com/ychun/p/17016917.html

相关文章

  • 9.Java异步编程
    一.JavaExecutor框架 Runnable接口和Callable接口都是对任务的抽象。java.util.concurrent.Executor接口则是对任务执行的抽象。 Executor接口功能有限,①只能为客户端......
  • How to Iterate HashMap in Java?
    https://www.geeksforgeeks.org/how-to-iterate-hashmap-in-java/ HashMap isapartofJava’scollectionprovidingthebasicimplementationoftheMapinterfa......
  • JAVA零基础小白上手教程day08-JAVAOOP面向对象
    day08-JAVAOOP课程目标1.【理解】什么是接口2.【掌握】接口的定义格式3.【掌握】接口的使用4.【理解】接口的成员特点5.【理解】类和接口抽象类和接口之间的关......
  • How to Maintain Insertion Order of the Elements in Java HashMap?
    https://www.geeksforgeeks.org/how-to-maintain-insertion-order-of-the-elements-in-java-hashmap/ Whenelementsgetfromthe HashMap duetohashingtheorder......
  • 生成JavaDoc文档
    javadoc在Dos命令中生成java文档打开.java所在文件目录目录上cmd\..\..javadoc-encodingUTF-8-charsetUTF-8Demo01.java生成index.html文件javadoc在IDEA生......
  • Selenium64-pytest.ini
    配置文件pytest.inipytest.ini是什么?pytest.ini是pytest的主配置文件,可以改变pytest的默认行为,有很多可配置的选项。在执行文件根目录配置pytest.ini文件。日志的......
  • Selenium65-Allure报告
    Allure简介Allure是一款轻量级并且非常灵活的开源测试报告框架。它支持绝大多数测试框架,例如TestNG、Pytest、JUint等。它简单易用,易于集成。官网:http://allure......
  • Selenium63-yaml文件
    提升维护性策略定位和操作都在page层,不方便维护方案:把定位从page层分离到element层。使用yaml作为element层描述元素定位条件的文件格式。YAML格式YAML(/ˈjæməl/......
  • Selenium62-使用POM的测试用例
    添加赛区脚本test_后台_双创_基础设置_赛区管理_添加赛区_case_v7.py导入各个网页对象改造to_division_manager导入各个网页对象导入各个网页对象:frompage.......
  • Selenium61-POM的Page基类
    POM是什么页面对象模型(POM)是一种设计模式,用来管理维护一组web元素集的对象库。在POM下,应用程序的每一个页面都有一个对应的pageclass每一个pageclass维护着该web......