webDriver + Firefox 浏览器 完美兼容
搞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 浏览器 完美兼容的更多相关文章
- Selenium Webdriver firefox 浏览器问题
Selenium Webdriver 在使用firefox 测试会牵扯到firefox的安装路径的问题 1.默认安装路径在c盘的情况下: WebDriver driver = new FirefoxD ...
- 解决Selenium与firefox浏览器版本不兼容问题
因为在用java打开firefox浏览器的时候报错 org.openqa.selenium.firefox.NotConnectedException: Unable to connect to ho ...
- js 完美兼容浏览器的复制功能
1,js结合swf的复制功能,完美兼容火狐,谷歌,360,ie8,使用示例:(ps:引入copy.swf比较重要,文件传送门 解压密码:http://www.bieanju.com/,为了防止360删 ...
- 【Selenium专题】WebDriver启动firefox浏览器
firefox浏览器不需要下载驱动,原生支持,以下是代码运行环境,firefox启动封装在方法startFirefox()中 import org.openqa.selenium.WebDriver; ...
- python+selenium webdriver.firefox()方式配置浏览器设置
webdriver.firefox() 爬虫需求: (其实是输入参数可获取.zip/pdf 文件,然后点击下载) ——但是firefox浏览器有Bug,点击下载之后会有弹出窗口,需要你点击确定,这怎 ...
- webdriver高级应用- 启动带有用户配置信息的firefox浏览器窗口
由于WebDriver启动FireFox浏览器时会启用全新的FireFox浏览器窗口,导致当前机器的FireFox浏览器已经配置的信息在测试中均无法生效,例如已经安装的浏览器插件.个人收藏夹等.为了解 ...
- webdriver学习笔记(一):webdrive脚本打开firefox浏览器,报“AttributeError: module 'selenium.webdriver' has no attribu
按照网上提供的方法: 下载geckodriver之后解压缩到 Firefox安装目录 下 添加 Firefox安装目录 到 系统变量Path 重启pycharm 照此步骤执行后,仍然报同样的错.折腾了 ...
- Webdriver启动Firefox浏览器后,页面显示空白
在使用pycharm码代码时编译总是出错,后来验证发现浏览器启动后出现问题.白白耗了我2个小时.我把我的解决方案写出来,希望对大家有帮助. 1.现象:起初安装的时候总是能正常运行,有一天突然发现Web ...
- 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 ...
随机推荐
- debug问题记录
debug进不去,发现断点没有带勾. 方案:去掉所有断点,重新编译,debug启动,重新打断点. source里面加入自己的java project. 关掉所有的java页面!!! dobbo服务用d ...
- 生产环境rac无法启动
节点二crs无法启动,查看启动日志:ohasd.log位置在/u01/app/11.2.0/grid/log/host01/ohasd/ohasd.log另外root.sh的log在rootcrs_X ...
- 恢复scout工具栏
删除scout安装路径 C:\PROGRAM FILES\SIEMENS\STEP7\U7UMC\DATA\WRKBNCH 下的三个文件: acppersi.dat uespersi.dat uesu ...
- vs2015编译纯ASM文件
x86: 1. 创建一个 C++ 的空项目. 2.解决方案管理器 - 目标项目名 - 右键 - 生成依赖项 - 生成自定义 (VS2015, 如果使用VS2010 你右键就直接能看到生成自定义) 3. ...
- 小故事学设计模式之Observer : (三) 老婆帮忙订机票
(IT的事就是过场多,过场多了就容易忘,所以我们不妨看一个记一个,这也是一个办法,顺便还能跟同行们交流一下) 要和老婆一起回老家了, 成都离我们安徽太远, 两个人飞一下过去就要花掉近三千块, 于是我 ...
- Softmax实现 fashion.mnist 分类
softmax #!/usr/bin/env python # coding: utf-8 # In[1]: get_ipython().run_line_magic('matplotlib', 'i ...
- BZOJ 2038: [2009国家集训队]小Z的袜子(hose) 【莫队算法模版】
任意门:https://www.lydsy.com/JudgeOnline/problem.php?id=2038 题意概括: 有 N 只袜子(分别编号为1~N),有 M 次查询 (L, R)里面随机 ...
- c语言实现数组的转置
#include<stdio.h> int main (){ int i,j,m,n; ][],b[][]; printf("请输入行列式的行数:\n"); scanf ...
- 解决 Database Configuration Assistannt安装oracle实例使的 警告
在创建到85%的时候报错,错误如下: 解决办法: 经过查看警告中给出的日志文件F:\develop\oracle_data\app\Administrator\cfgtoollogs\dbca\tes ...
- Android学习笔记_50_(转 四种加载方式详解(standard singleTop singleTask singleInstance)
Android之四种加载方式 (http://marshal.easymorse.com/archives/2950 图片) 在多Activity开发中,有可能是自己应用之间的Activity跳转,或 ...