zoukankan      html  css  js  c++  java
  • Selenium驱动Firefox浏览器

    用Maven构建Selenium依赖:

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

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;

    public class Firefox {
    public static void main(String[] args) throws InterruptedException {
    System.setProperty("webdriver.firefox.marionette", "src/main/resourcec/geckodriver.exe");
    //指定Firefox浏览器驱动的路径,使用相对路径
    String baiduHomePage;
    baiduHomePage = "https://www.baidu.com/";
    //百度首页的地址

    WebDriver driver;
    //声明一个WebDriver
    driver = new FirefoxDriver();
    driver.manage().window().maximize();
    //使浏览器窗口最大化
    driver.get(baiduHomePage);
    //打开百度
    Thread.sleep(2000);
    //强制线程等待2秒钟
    assert driver.getTitle().equals("百度一下,你就知道");
    //断言页面标题

    driver.findElement(By.xpath(".//*[@id='kw']")).sendKeys("Selenium");
    //在百度搜索输入框输入“Selenium”
    driver.findElement(By.xpath(".//*[@id='su']")).click();
    //点击搜索按钮
    Thread.sleep(2000);
    assert driver.getTitle().equals("Selenium_百度搜索");

    driver.close();
    //关闭浏览器窗口
    driver.quit();
    //结束dirver
    }
    }

    需要注意的是,
    Firefox浏览器不能是官网上最新的版本,
    否则会出现启动了浏览器,
    却无法打开网址的情况;
    我用的版本是:
    Firefox-v52.5.3-win64
    驱动的版本是:
    geckodriver-v0.19.1-win64
     


  • 相关阅读:
    sql server 的存储过程
    vue SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    数据结构 基本概念和术语
    vue v-show指令
    vue v-model :
    vue 指令
    vue 挂载点 实例 模板
    vue(1) 第一个例子
    【BZOJ1150】[CTSC2007]数据备份Backup 双向链表+堆(模拟费用流)
    【BZOJ1109】[POI2007]堆积木Klo 二维偏序
  • 原文地址:https://www.cnblogs.com/yjlch1016/p/8320792.html
Copyright © 2011-2022 走看看