webDriver + Firefox 浏览器 完美兼容
来源:互联网 发布:小米笔记本 显卡知乎 编辑:程序博客网 时间:2024/05/17 04:42
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.
阅读全文
0 0
- webDriver + Firefox 浏览器 完美兼容
- webdriver启动firefox浏览器
- 完美的hr-兼容各个浏览器firefox,ie6,ie7
- 完美的hr-兼容各个浏览器firefox,ie6,ie7
- webdriver css 缩放浏览器 Firefox
- Selenium Webdriver firefox 浏览器问题
- Webdriver Selenium与Firefox 版本兼容
- 让旧版本Firefox扩展完美兼容新版浏览器的小技巧
- WebDriver打开firefox浏览器崩溃问题解决方法
- webdriver-firefox浏览器获取本地路径格式
- Firefox浏览器完美运行Firefox OS
- Firefox浏览器兼容JS脚本供参考
- Firefox浏览器兼容JS脚本供参考
- Firefox浏览器兼容Javascript脚本的方法
- Javascript兼容IE和Firefox浏览器技巧
- 浏览器兼容:IE6,IE7,IE8,FIREFOX,Chrome
- 浏览器兼容:IE6,IE7,IE8,FIREFOX,Chrome
- 兼容IE,firefox浏览器回车事件
- The path to the driver executable must be set by the webdriver.gecko.driver system property
- 操作符*或者->的重载
- Android 线性布局参数
- 值和引用&装箱拆箱
- 获取焦点demo(一)
- webDriver + Firefox 浏览器 完美兼容
- 日本中学校偏差値一覧
- 最大和
- RabbitMQ简述
- 关于SVM的一些思考
- 罗永浩跟罗振宇八个半小时都聊了些什么
- 排序算法之堆排序
- (七)Paint 高级渲染
- 【java-算法】连续数组最大和