首先这次使用的webDriver for Firefox的

由于项目的原因,需要在测试的时候加载Firebug和使用vpn,加载代理

Firefox 加载代理,可以从FF菜单上看,代理分为好几种

我这里使用的是type 为2 的情况

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 2);
profile.setPreference("network.proxy.autoconfig_url", "http://proxy.myweb.com:8083"); //自动代理配置
WebDriver driver = new FirefoxDriver(profile);

如果type 为1 ,需要这么设置

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 1); profile.setPreference("network.proxy.http", "proxy.domain.example.com");
profile.setPreference("network.proxy.http_port", 8080);
profile.setPreference("network.proxy.ssl", "proxy.domain.example.com");
profile.setPreference("network.proxy.ssl_port", 8080);
profile.setPreference("network.proxy.ftp", "proxy.domain.example.com");
profile.setPreference("network.proxy.ftp_port", 8080);
profile.setPreference("network.proxy.socks", "proxy.domain.example.com");
profile.setPreference("network.proxy.socks_port", 8080);
WebDriver driver = new FirefoxDriver(profile);
public class sfLogin {
static String company="autoPM2CandU";
static String user="athompson";
static String password="pwd"; public static void main(String[] args) {
// TODO Auto-generated method stub
WindowsUtils.tryToKillByName("firefox.exe");
WindowsUtils.getProgramFilesPath();
WebDriver driver=DriverFactory.getFirefoxDriver();
driver.get("https://qaautocand.successfactors.com/login");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS); WebElement comp=driver.findElement(By.xpath("//*[@id='company']"));
Actions actions =new Actions(driver);
actions.sendKeys(Keys.F12).perform();//.keyUp(Keys.F12)
WebElement username=driver.findElement(By.xpath("//*[@id='username']"));
WebElement passwordHints=driver.findElement(By.xpath("//*[@id='passwordHints']")); passwordHints.click();
WebElement pw=driver.findElement(By.xpath("//*[@id='password']")); WebElement login=driver.findElement(By.xpath("//*[@id='loginSubmitBtn']"));
comp.sendKeys(company);
username.sendKeys(user);
passwordHints.click();
pw.sendKeys(password);
login.submit(); WebElement home=driver.findElement(By.xpath("//*[@id='8:label']")); actions.moveToElement(home).click().build().perform();
WebElement performance=driver.findElement(By.xpath("//*[@id='10:2']"));
performance.click(); WebElement endBox=driver.findElement(By.xpath("//*[@id='tablist']/tbody/tr[2]/td/div/div/div/table/tbody/tr[3]/td[2]/a")); endBox.click(); WebElement auditTrailButton =driver.findElement(By.xpath("//*[@id='form_list_table']/tbody/tr/td[10]/a[2]/img"));
auditTrailButton.click(); WebElement action =driver.findElement(By.xpath("//*[@id='contentBodyTable']/tbody/tr[2]/td/div[2]/div/div[2]/div/div/div[2]/div/table/tbody/tr/td/table[2]/tbody/tr[2]/td/table/tbody/tr[4]/td/table/tbody/tr[4]/td[9]")); System.out.println(action.getText()); } }

如果需要加载firebug

    File file=new File("d:\\firebug-2.0.4-fx.xpi");//设置Firebug路径
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 1); profile.setPreference("network.proxy.http", "proxy.domain.example.com");
profile.setPreference("network.proxy.http_port", 8080);
profile.setPreference("network.proxy.ssl", "proxy.domain.example.com");
profile.setPreference("network.proxy.ssl_port", 8080);
profile.setPreference("network.proxy.ftp", "proxy.domain.example.com");
profile.setPreference("network.proxy.ftp_port", 8080);
profile.setPreference("network.proxy.socks", "proxy.domain.example.com");
profile.setPreference("network.proxy.socks_port", 8080); try {
profile.addExtension(file);
profile.setPreference("extensions.firebug.currentVersion", "2.0.4");//设置firebug 版本
} catch (IOException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
} WebDriver driver = new FirefoxDriver(profile);
return driver;

如果需要在运行时候firebug执行

Actions actions =new Actions(driver);
actions.sendKeys(Keys.F12).perform();//使用F12调出firebug

扩展,为什么这么设置

你可以使用about:config 在Firefox里边看看

Selenium FF WebDriver 加载firebug 和设置代理的更多相关文章

  1. Selenium FF WebDriver运行时开启firebug的2种方式

    上一次我实测FF webdriver 加载firefoxhttp://www.cnblogs.com/tobecrazy/p/3997375.html 那么问题就来了,既然能加载firebug能否在运 ...

  2. js不需要知道图片宽高的懒加载方法(经过实际测试,不加宽高仍然是无法正常加载的,设置height:auto,height:100%,仍然显示高度为0)

    js不需要知道图片宽高的懒加载方法 懒加载是如何实现的? - 简书https://www.jianshu.com/p/e86c61468285找到一个不需要知道图片宽高的懒加载方法了(经过实际测试,不 ...

  3. selenium2入门 用selenium安装、加载、启用插件(一)

    一:下载 下载地址是:http://docs.seleniumhq.org/download/

  4. selenium2 用selenium安装、加载、启用插件(一)

    一:下载 下载地址是:http://docs.seleniumhq.org/download/

  5. selenium自动化之加载浏览器的配置文件

    做seleniumUI自动化关于选用哪个浏览器方面,对于我来说,火狐浏览器只是用于定位元素,因为有firebug(注意高版本的火狐已经安装不了这个插件了),而真正执行自动化脚本用的是谷歌,感觉谷歌的速 ...

  6. selenium 等待页面加载完成

    一.隐形加载等待: file:///C:/Users/leixiaoj/Desktop/test.html 该页面负责创建一个div <html> <head> <tit ...

  7. Selenium WebDriver- 指定页面加载时间

    #encoding=utf-8 import unittest import time from selenium import webdriver from selenium.webdriver i ...

  8. Selenium 的页面加载以及几种等待的问题

    1. PageLoadStrategy : 当调用driver.get("https://xxxx.xxx.xxx")来访问某页面时,get方法通常会阻塞浏览器直到页面完全加载后才 ...

  9. python3 selenium 超时停止加载,并且捕捉异常, 进行下一步【亲测有效】

    from selenium import webdriver import os import re class GetPage: def __init__(self, url_path): self ...

随机推荐

  1. 线程join理解

    1.python默认参数创建线程后,不管主线程是否执行完毕,都会等待子线程执行完毕才一起退出,有无join结果一样 2.如果创建线程,并且设置了daemon为true,即thread.setDaemo ...

  2. vue.js之过渡效果-css

    概述 vuejs的过渡效果可以让我们的页面元素在出现和消失时实现过渡.官方文档这样描述过渡效果的方式: 在 CSS 过渡和动画中自动应用 class 可以配合使用第三方 CSS 动画库,如 Anima ...

  3. Uncaught RangeError: Maximum call stack size exceeded 超出最大调用值(个人解释)

    写了段jq后,报这个错,度娘未解,灵光一闪,找到原因,上代码: Html 结构: <a href="javascript:;" class="item-pic&qu ...

  4. 使用视 meta 标签来控制手机浏览器布局

    移动浏览器的Fennec一样呈现在一个虚拟的"窗口"页面(视),通常比屏幕宽.所以他们不需要去挤每个页面布局到一个小窗口(这会破坏许多非移动优化的网站) .用户可以平移和缩放才能看 ...

  5. Django初识

    web框架 Web应用框架有助于减轻网页开发时共通性活动的工作负荷,例如许多框架提供数据库访问接口.标准样板以及会话管理等,可提升代码的可再用性.简单地说,就是你用别人搭建好的舞台来做表演,用别人做好 ...

  6. Java多线程与并发库高级应用-面试题

    第一题:现有的程序代码模拟产生了16个日志对象,并且需要运行16秒才能打印完这些日志,请在程序中增加4个线程去调用parseLog()方法来分头打印这16个日志对象,程序只需要运行4秒即可打印完这些日 ...

  7. View的绘制、事件传递过程

    View绘制过程 onMeasure() onLayout() onDraw() 过程详解 onMeasure() 计算尺寸 onLayout() 为viewGroup类型布局子视图用的. onDra ...

  8. iBatis.net 类的继承extends和懒加载

    <resultMaps> <resultMap id="FullResultMap" class="t_c_team_member_permission ...

  9. 【原创】JEECMS v6~v7任意文件上传漏洞(2)

    文章作者:rebeyond 受影响版本:v6~v7 漏洞说明: JEECMS是国内Java版开源网站内容管理系统(java cms.jsp cms)的简称.该系统基于java技术开发,继承其强大.稳定 ...

  10. 关于JSF中immediate属性的总结(三)

    Okay, when should I use the immediate attribute? If it isn't entirely clear yet, here's a summary, c ...