Selenium FireFoxDriver Profile changing after loading firefox?

前端 未结 3 696
夕颜
夕颜 2021-01-07 09:48
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile(\"default\");//using firefox default profile
ffprofile.setPreference(\"permiss         


        
3条回答
  •  伪装坚强ぢ
    2021-01-07 10:42

    Since the dev toolbar CLI does not work for me (since the key combination does not open the CLI) here is how I managed to change profile settings of a running firefox instance:

            IWebDriver driver = //your instance
            driver.Navigate().GoToUrl("about:config");
            driver.FindElement(By.Id("warningButton")).Click();
            IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
    
            js.ExecuteScript("window.Services.prefs.setIntPref('permissions.default.image', " + 2 + ")");
    

    It's C# but the conversion in Java should not be too hard. The idea is that the about:config tab declares a lot of Javascript object allowing to change the profile settings, so we just have to go on that page and to execute some JS code.

提交回复
热议问题