搞java最烦的就是不同版本的适配问题。现分享下实测成功的案例。

Firefox:4.0.1

selenium:selenium-server-standalone-2.43.1.jar

下面这个链接就有以上两个文件。

http://pan.baidu.com/s/1nvD503f

火狐历史版本下载列表: http://ftp.mozilla.org/pub/firefox/releases/4.0.1/win32/zh-CN/

selenium-server-standalone-2.43.1.jar 需要以文件扩展的形式加入到 Firefox浏览器中。

package com.****.main;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver; public class Main { public static void main(String[] args) {
// TODO Auto-generated method stub // webdriver.chrome.driver C:\Users\Administrator\AppData\Local\Google\Chrome\Application\chrome.exe /*System.setProperty("webdriver.chrome.driver", "C:/Users/Administrator/AppData/Local/Google/Chrome/Application/chrome.exe");
WebDriver driver = new ChromeDriver();*/ System.setProperty("webdriver.firefox.bin", "C:/Program Files (x86)/Mozilla Firefox/firefox.exe");
WebDriver driver = new FirefoxDriver(); //Puts a Implicit wait, Will wait for 10 seconds before throwing exception
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); //Launch website
driver.navigate().to("http://www.baidu.com/"); //Maximize the browser
driver.manage().window().maximize(); String strTxt=driver.getPageSource(); System.out.println(strTxt); /*// Click on Math Calculators
driver.findElement(By.xpath(".//*[@id='menu']/div[3]/a")).click(); // Click on Percent Calculators
driver.findElement(By.xpath(".//*[@id='menu']/div[4]/div[3]/a")).click(); // Enter value 10 in the first number of the percent Calculator
driver.findElement(By.id("cpar1")).sendKeys("10"); // Enter value 50 in the second number of the percent Calculator
driver.findElement(By.id("cpar2")).sendKeys("50"); // Click Calculate Button
driver.findElement(By.xpath(".//*[@id='content']/table/tbody/tr/td[2]/input")).click(); // Get the Result Text based on its xpath
String result = driver.findElement(By.xpath(".//*[@id='content']/p[2]/span/font/b")).getText(); //Print a Log In message to the screen
System.out.println(" The Result is " + result);*/ //Close the Browser.
driver.close();
} }

项目中需要加入上面下载包中的标红,jar包。

java代码运行效果如下:

转载请注明出处:http://www.cnblogs.com/jackicalSong/

The End.

webDriver + Firefox 浏览器 完美兼容的更多相关文章

  1. Selenium Webdriver firefox 浏览器问题

    Selenium Webdriver 在使用firefox 测试会牵扯到firefox的安装路径的问题 1.默认安装路径在c盘的情况下: WebDriver driver = new FirefoxD ...

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

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

  3. js 完美兼容浏览器的复制功能

    1,js结合swf的复制功能,完美兼容火狐,谷歌,360,ie8,使用示例:(ps:引入copy.swf比较重要,文件传送门 解压密码:http://www.bieanju.com/,为了防止360删 ...

  4. 【Selenium专题】WebDriver启动firefox浏览器

    firefox浏览器不需要下载驱动,原生支持,以下是代码运行环境,firefox启动封装在方法startFirefox()中 import org.openqa.selenium.WebDriver; ...

  5. python+selenium webdriver.firefox()方式配置浏览器设置

    webdriver.firefox() 爬虫需求:  (其实是输入参数可获取.zip/pdf 文件,然后点击下载) ——但是firefox浏览器有Bug,点击下载之后会有弹出窗口,需要你点击确定,这怎 ...

  6. webdriver高级应用- 启动带有用户配置信息的firefox浏览器窗口

    由于WebDriver启动FireFox浏览器时会启用全新的FireFox浏览器窗口,导致当前机器的FireFox浏览器已经配置的信息在测试中均无法生效,例如已经安装的浏览器插件.个人收藏夹等.为了解 ...

  7. webdriver学习笔记(一):webdrive脚本打开firefox浏览器,报“AttributeError: module 'selenium.webdriver' has no attribu

    按照网上提供的方法: 下载geckodriver之后解压缩到 Firefox安装目录 下 添加 Firefox安装目录 到 系统变量Path 重启pycharm 照此步骤执行后,仍然报同样的错.折腾了 ...

  8. Webdriver启动Firefox浏览器后,页面显示空白

    在使用pycharm码代码时编译总是出错,后来验证发现浏览器启动后出现问题.白白耗了我2个小时.我把我的解决方案写出来,希望对大家有帮助. 1.现象:起初安装的时候总是能正常运行,有一天突然发现Web ...

  9. Selenium2学习-007-WebUI自动化实战实例-005-解决 Firefox 版本不兼容:org.openqa.selenium.WebDriverException: Failed to connect to binary FirefoxBinary

    此文主要讲述 Java 运行 Selenium 脚本时,因 Friefox 浏览器版本与 selenium-server-standalone-x.xx.x.jar 不兼容引起的 org.openqa ...

随机推荐

  1. leetcode 62、Unique Paths

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...

  2. [原]Machine Learing 入门 —— 开门第0篇

    一.最近懒了 7月没怎么写博客,倒是一直在学Machine Learning的入门知识,在这里给大家推荐一个不错的自学网站:https://www.coursera.org/ ,Andrew Ng是联 ...

  3. WPF产生不重复的随机数

    WPF产生不重复的随机数 在给定的区间范围(比如[50,99]),产生给定数量的随机数(不如10个),要求产生的随机数不重复首先给定变量min=50;max=99+1;//习惯与程序规定的编码不同所致 ...

  4. 【[SDOI2014]旅行】

    听说这是动态开点主席树的板子题,但是发现我还不会,于是就来写一写 其实跟主席树一个样子的 这里就是存个板子吧 #include<cstdio> #include<cstring> ...

  5. DEM、DTM和DSM的区别

    一.DTM(Digital Terrain Model) 数字地面模型是利用一个任意坐标系中大量选择的已知x.y.z的坐标点对连续地面的一个简单的统计表示,或者说,DTM就是地形表面形态属性信息的数字 ...

  6. Java to Kotlin (1) - 就决定是你了

    2017年,Kotlin的发展可谓十分迅猛,稍微关注it界的人都知道谷歌宣布kotlin成为安卓的一级语言,不过那时候我并没有关注,因为我不是搞安卓的... 哈哈开个玩笑,其实之前也有听说过这个语言的 ...

  7. css3中有关transform的问题

    Transform属性应用于元素的2D或3D转换.这个属性允许你将元素旋转,缩放,移动,倾斜等.

  8. 自己理解的数据库shcema

    不懂就被人嘲笑呀 ,你还不知道怎么说. 从定义中我们可以看出schema为数据库对象的集合,为了区分各个集合,我们需要给这个集合起个名字,这些名字就是我们在企业管理器的方案下看到的许多类似用户名的节点 ...

  9. Sass 基础(六)

    join() 函数 join()函数是将两个列表连接合并成一个列表. >>join(10px 20px, 30px 40px) (10px 20px 20px 40px) >> ...

  10. TCP三次挥手四次握手

    三次握手: 客户端发起: 1.向服务器端发送报文SYN=1,ACK=0;客户端进入SYN-SEND状态. 2.服务端收到SYN=1,ACK=0的请求报文,向客户端返回确认报文SYN=1,ACK=1,服 ...