2016-09-20 77 views
0

我需要您的幫助來使用Firebug設置我的Firefox配置文件。我想要的是當我通過Selenium WebDriver啓動它時,Firebug插件將被加載Firefox實例。這裏是我的代碼示例:Selenium和Firefox配置文件設置

final File file = new File("C:\\Program Files (x86)\\Gecko\\bin\\geckodriver.exe"); 
System.setProperty("webdriver.gecko.driver", file.getAbsolutePath()); 
FirefoxProfile profile = new FirefoxProfile(); 
profile.setPreference("?"); 

所以...我怎麼可以設置setPreference值,使螢火蟲與Firefox的加載一起當硒的webdriver啓動瀏覽器?

+0

Kotoj ..非常感謝跟進我的問題。這裏是代碼:final File file = new File(「C:\\ Program Files(x86)\\ Gecko \\ bin \\ geckodriver.exe」); System.setProperty(「webdriver.gecko.driver」,file.getAbsolutePath()); final String firebugPath =「C:\\ Users \\ jnguyen \\ AppData \\ Roaming \\ Mozilla \\ Firefox \\ Profiles \\ erx927l4.default \\ extensions \\ [email protected]」; FirefoxProfile profile = new FirefoxProfile(); profile.addExtension(new File(firebugPath)); driver = new FirefoxDriver(profile); –

回答

0

你要添加擴展,而不是設置的偏好:

final String firebugPath = "C:\\FF_Profile\\firebug.xpi"; 
FirefoxProfile profile = new FirefoxProfile();   
profile.addExtension(new File(firebugPath)); 
WebDriver driver = new FirefoxDriver(profile); 

你可以找到下面這說明Firebug的路徑:

https://stackoverflow.com/a/8074828/432681

+1

Kotoj!很好的信息。感謝您抽出我的時間詢問。很好的幫助! –

+0

我的榮幸,如果我的答案幫助,請接受它;) – kotoj

+0

kotoj ...我試過,但它似乎不工作....沒有錯誤信息..所以我不知道爲什麼它不工作?無論如何感謝kotoj! –

0

Kotoj

這裏是代碼:

//告訴黃瓜在geckodriver位於環境

final File file = new File("C:\\Program Files (x86)\\Gecko\\bin\\geckodriver.exe"); 


// Get the absolute path to the Gecko Driver 
System.setProperty("webdriver.gecko.driver", file.getAbsolutePath()); 


final String firebugPath= "C:\\Users\\<My username>\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\erx927l4.default\\extension s\\[email protected]"; 


// Set up the Firefox browser profile 
FirefoxProfile profile = new FirefoxProfile(); 


profile.addExtension(new File(firebugPath)); 


// bring up the browser 
driver = new FirefoxDriver(profile); 

我想這些代碼添加到評論部分,但它不會讓我格式化文本,所以我必須張貼在「後你的答案「部分..對不起

相關問題