如何在firefox中传递jsconsole参数以启动浏览器控制台?

时间:2018-07-17 19:32:05

标签: firefox selenium-webdriver mozilla

I would like to open **Browser Console** for my session every time I launch Firefox. 

Browser : Firefox  v 61 

How can you launch Browser Console for firefox:
1. open firefox (and give any URL )
2. Press Ctrl+Shift+J (or Cmd+Shift+J on a Mac) 

Link : https://developer.mozilla.org/en-US/docs/Tools/Browser_Console


else if (browser.Equals(Constant.Firefox))
 {
     var profileManager = new FirefoxProfileManager();
     FirefoxProfile profile = profileManager.GetProfile("ConsoleLogs");
     FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(DrivePath);
     service.FirefoxBinaryPath = DrivePath;
     profile.SetPreference("security.sandbox.content.level", 5);
     profile.SetPreference("dom.webnotifications.enabled", false);
     profile.AcceptUntrustedCertificates = true;              
     FirefoxOptions options = new FirefoxOptions();                
     options.AcceptInsecureCertificates = true;
     options.Profile = profile;
     options.SetPreference("browser.popups.showPopupBlocker", false);
     driver = new FirefoxDriver(service.FirefoxBinaryPath, options, TimeSpan.FromSeconds(100));
     driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);            
 }

我试图创建一个bat文件并将其提供给我的代码,但是这个批处理文件 创建一个新的-单独的Firefox浏览器会话,这不是我想要的,我想为当前会话启动浏览器控制台以实现自动化。

cd C:\Program Files\Mozilla Firefox 
firefox -jsconsole
pause

此代码:

 Process p = new Process();
 p.StartInfo.FileName = @"C:\Users\Com\Desktop\batch\FirefoxConsole.bat";
 p.Start();
 Thread.Sleep(2000);

我现在正在寻找什么: 如果可以的话,我想在我的Selenium Firefox配置文件中传递“ -jsconsole”。

C:\ Program Files \ Mozilla Firefox> firefox.exe -jsconsole

,我不知道该怎么做。

1 个答案:

答案 0 :(得分:0)

we just need to add this line in code where we initialing Firefox 

options.AddArgument("--jsconsole");

else if (browser.Equals(Constant.Firefox))
 {
     var profileManager = new FirefoxProfileManager();
     FirefoxProfile profile = profileManager.GetProfile("ConsoleLogs");
     FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(DrivePath);
     service.FirefoxBinaryPath = DrivePath;
     profile.SetPreference("security.sandbox.content.level", 5);
     profile.SetPreference("dom.webnotifications.enabled", false);
     profile.AcceptUntrustedCertificates = true;              
     FirefoxOptions options = new FirefoxOptions();
     **options.AddArgument("--jsconsole");**                
     options.AcceptInsecureCertificates = true;
     options.Profile = profile;
     options.SetPreference("browser.popups.showPopupBlocker", false);
     driver = new FirefoxDriver(service.FirefoxBinaryPath, options, TimeSpan.FromSeconds(100));
     driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);            
 }