WebDriver每次启动时可能都会创建新的或者使用默认的profile,所以在浏览器中添加了插件,并设置好后下次重启就没有了,需要手动设置一下profile的路径才能够保存,方法以加载插件image block X为例
- create firefox profile:start firefox profile manager cd ./profile/firefox firefox -p and create a new profile, select folder “./profile/firefox”, named “firefox-esr”(anything else)
- enter “about:config” in address bar of Firefox, search ‘xpi’
change the following properties to false:
xpinstall.signatures.required
xpinstall.whitelist.required
- install image block x: Menu -> Add-ons -> Extensions -> Install add-on from file, select the file: extensions/firefox/image-block-x.xpi
- start firefox with the new firefox profile: firefox -p and select the profile “firefox-esr”, “start firefox”
- go to setup the white list and click “image block x” button to enable image block and quit firefox
设置好profile后,在启动webdriver时自动加载
const Selenium = require('selenium-webdriver');
const firefox = require('selenium-webdriver/firefox');
let profile = './profile/xxxx.firefox-esr';
options=new firefox.Options();
if( fs.existsSync(profile)){
options.setProfile(profile);
}
let builder = new Selenium.Builder().forBrowser(Selenium.Browser.FIREFOX);
let driver = await builder.build();