首先搭建火狐插件開發環境:javascript
而後編寫一個簡單的firefox插件java
var buttons = require('sdk/ui/button/action'); var tabs = require("sdk/tabs"); var button = buttons.ActionButton({ id: "mozilla-link", label: "Visit Mozilla", icon: { "16": "./icon-16.png", "32": "./icon-32.png", "64": "./icon-64.png" }, onClick: handleClick }); function handleClick(state) { tabs.open("https://www.mozilla.org/"); }
插件編寫參考自:https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Getting_startedpython
最後一步就是在selenium中使用了,沒用過selenium的朋友能夠不看下面的web
System.setProperty("webdriver.firefox.bin", "D:/Program Files (x86)/Mozilla Firefox/firefox.exe"); TemporaryFilesystem.setTemporaryDirectory(new File( "D:/workspace/firefox/seleniumTemp/")); FirefoxProfile firefoxProfile = new FirefoxProfile(new File( "D:/workspace/firefox/profiles/test/")); File cookieWriter = new File("rwfile.xpi"); try { firefoxProfile.addExtension(cookieWriter); //設置插件相關參數 參數格式爲 extensions.插件名.參數名 // 設置插件版本 firefoxProfile.setPreference("extensions.rwfile.currentVersion", "1.0"); //默認狀況下經過selenium加載的插件是被火狐禁用的,設置下面幾個參數就能夠啓用了 firefoxProfile.setPreference( "extensions.rwfile.console.enableSites", true); firefoxProfile.setPreference("extensions.rwfile.net.enableSites", true); firefoxProfile.setPreference( "extensions.rwfile.script.enableSites", true); firefoxProfile.setPreference( "extensions.rwfile.allPagesActivation", "on"); } catch (IOException e) { e.printStackTrace(); } WebDriver driver = new FirefoxDriver(firefoxProfile); driver.get("http://www.xhalj.com/");