Selenium FF WebDriver 加载firebug 和设置代理
首先这次使用的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里边看看
转载请注明出处:http://www.cnblogs.com/tobecrazy/

【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?