用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
 
												

Selenium驱动Firefox浏览器的更多相关文章

  1. 解决selenium驱动Firefox跳转页慢慢慢的问题

    首先我给自己定义为是一个更新偏执狂.不知道从哪个版本开始,使用selenium驱动打开Firefox浏览器时,会跳转到官网指定页,这个过程真是慢得要死. 为了解决这个问题,我是查了很多资料,解决方案是 ...

  2. selenium驱动Firefox跳转页慢慢慢的问题(待验证)

    转载至http://www.cnblogs.com/yicaifeitian/p/5198871.html 为了解决这个问题,我是查了很多资料,解决方案是百度出来的.抱歉,我忘记出处在哪了,代码如下: ...

  3. 7.解决在python中用selenium启动FireFox浏览器启动不了的方法

    首次在利用python中的selenium启动FireFox浏览器时可能碰到如下问题 当输入如下代码时: from selenium import webdriver brower=webdriver ...

  4. Java编程语言下Selenium驱动各个浏览器代码

    这里采用的是Selenium3.7版本,首先介绍的是在Windows环境下运行的: 总结下注意事项: 1,设置各个浏览器的Driver路径 System.setProperty("" ...

  5. Java编程语言下 Selenium 驱动各个浏览器代码

    这里采用的是Selenium3.7版本,首先介绍的是在Windows环境下运行的: 总结下注意事项: 1,设置各个浏览器的Driver路径 System.setProperty("" ...

  6. 解决Selenium与firefox浏览器版本不兼容问题

    因为在用java打开firefox浏览器的时候报错 org.openqa.selenium.firefox.NotConnectedException: Unable to connect to ho ...

  7. selenium驱动chrome浏览器问题

    selenium是一个浏览器自动化测试框架,以下介绍其如何驱动chrome浏览器? 1.下载与本地chrome版本对应的chromedriver.exe ,下载地址为http://npm.taobao ...

  8. 爬虫动态渲染页面爬取之selenium驱动chrome浏览器的使用

    Selenium是一个用于Web应用程序测试的工具.Selenium测试直接运行在浏览器中,就像真正的用户在操作一样,可以用其进行网页动态渲染页面的爬取. 支持的浏览器包括IE(7, 8, 9, 10 ...

  9. (原创)如何使用selenium 驱动chrome浏览器并且打开方式为手机模式-转载请注明出处

    随着移动设备使用率的不断增加,移动页面的测试也变得越来越重要. 对于互联网公司M站的测试,如果不通过专用的appium等移动端测试工具是否还有方便快捷的办法呢?答案当然是有啊. 使用chrome dr ...

随机推荐

  1. Positioning-Based Photo Retrieval

    MMAI 2015 FINAL PROJECT   To Know Where We Are: Positioning-based Photo Retrieval   2015/12/16 Updat ...

  2. 【洛谷P3469】[POI2008]BLO-Blockade

    BLO-Blockade 题目链接 若一个点为割点:统计出每个子树的大小,两两相乘再相加, 再加上n-1,为这个点与其他点的拜访数, 因为拜访是互相的,最后再乘二即可 若一个点不是割点:只有(n-1) ...

  3. 【luogu P3128 [USACO15DEC]最大流Max Flow】 题解

    题目链接:https://www.luogu.org/problemnew/show/P3128 菜 #include <cstdio> #include <cstring> ...

  4. Storm处理流程, 基本参数配置

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAksAAAG/CAYAAABIVpOQAAAABHNCSVQICAgIfAhkiAAAIABJREFUeF

  5. override render 方法

    有时候需要在ASP.net  或MVC 中在页面呈现前,把要显示的内容作一个拦截,更改内容后显示. 只要重写 protected override void Render(System.Web.UI. ...

  6. Visual Studio 2015 Tools for Unity安装

    https://blogs.msdn.microsoft.com/visualstudio/tag/visual-studio-tools-for-unity/ 下载对应的VS版本 里边可以找到下载地 ...

  7. Long数组转String数组

    public static String[] longToString(Long longArray[]) { if (longArray == null || longArray.length &l ...

  8. 开发的服务集群部署方案,以etcd为基础(java)

    当前有很多服务集群部署,但是对于我们自己开发的服务系统怎么样能够解决部署问题,对大家很麻烦和笨重. 首先,我想说对于我们国内,小公司小系统比较多.大型系统毕竟少数,向阿里云看齐的不多.其实所谓的需要集 ...

  9. 【TOJ 1912】487-3279(hash+map)

    描述 Businesses like to have memorable telephone numbers. One way to make a telephone number memorable ...

  10. Python实现trim函数

    Python中其实也有类似Java的trim函数的,叫做strip,举例: #!/usr/bin/python # -*- coding: UTF-8 -*- str = "0000000h ...