搞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. 笨办法学Python(四十一)

    习题 41: 来自 Percal 25 号行星的哥顿人(Gothons) 你在上一节中发现 dict 的秘密功能了吗?你可以解释给自己吗?让我来给你解释一下,顺便和你自己的理解对比看有什么不同.这里是 ...

  2. 同时开左右两个SAPGUI编辑器显示同一段ABAP代码

    很多文本编辑器都支持同时开左右两个窗口显示同一段代码,使用场景可能是比较同一段代码的不同版本差异,或者是ABAP里,同一段代码在Netweaver不同版本里的实现差异,比如版本为SP1的系统A和版本为 ...

  3. IOS 远程推送通知(UIRemoteNotification)

    ●  什么是远程推送通知 ●  顾名思义,就是从远程服务器推送给客户端的通知(需要联网) ●  远程推送服务,又称为APNs(Apple Push Notification Services) ●   ...

  4. js 原生获取Class元素

    function getElementsByClassName(n) { var classElements = [] allElements = document.getElementsByTagN ...

  5. 【洛谷P1073】[NOIP2009]最优贸易

    最优贸易 题目链接 看题解后感觉分层图好像非常NB巧妙 建三层n个点的图,每层图对应的边相连,权值为0 即从一个城市到另一个城市,不进行交易的收益为0 第一层的点连向第二层对应的点的边权为-w[i], ...

  6. 【luogu P3384 树链剖分】 模板

    题目链接:https://www.luogu.org/problemnew/show/P3384 诶又给自己留了个坑..不想写线段树一大理由之前的模板变量名太长 #include <cstdio ...

  7. HDU 1180 诡异的楼梯(超级经典的bfs之一,需多回顾)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1180 诡异的楼梯 Time Limit: 2000/1000 MS (Java/Others)     ...

  8. Entity Framework 五

    连接情景中的CRUD操作: 连接场景中的CRUD操作是一项相当简单的任务,因为默认情况下,上下文会自动跟踪实体在其生命周期中发生的更改,前提是AutoDetectChangesEnabled为true ...

  9. 前端html,css基础总结

    0.1.css引入界面的方式: 内联式:通过标签的style属性,在标签上直接写样式. <div style="width:100px; height:100px; backgroun ...

  10. 兼容性良好的 sticky-footer 布局

    <div class="content"> <div class="content-wrapper"> <div class=&q ...