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
     


  • 相关阅读:
    eclipse插件
    01 vue入门
    jrebel
    html5,css3炫酷实例-元素
    css文字实例锦集
    海外短信故障已经恢复
    证实海外(含港澳台)短信业务故障
    预计维护时间将延长
    黑龙江地区电信运营商业务中断
    正在进行计划中的停机维护
  • 原文地址:https://www.cnblogs.com/yjlch1016/p/8320792.html
Copyright © 2011-2022 走看看