How to pass the capabilities and options into Firefoxdriver using Selenium through Java

后端 未结 2 1516
余生分开走
余生分开走 2021-01-27 01:51

I have this:

System.setProperty(\"webdriver.gecko.driver\", \"gecko/linux/geckodriver\");

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference(\         


        
2条回答
  •  感情败类
    2021-01-27 02:40

    you can pass capabilities into firefoxoptions constructor as below :

    System.setProperty("webdriver.gecko.driver", "gecko/linux/geckodriver");
    
       FirefoxProfile profile = new FirefoxProfile();
       profile.setPreference("network.proxy.no_proxies_on", "localhost");
       profile.setPreference("javascript.enabled", true);
    
       DesiredCapabilities capabilities = DesiredCapabilities.firefox();
       capabilities.setCapability("marionette", true);
    
       FirefoxOptions options = new FirefoxOptions(capabilities);
    
    set profile to firefox options
       options.setProfile(profile);
       options.setLogLevel(Level.FINEST);
       options.addPreference("browser.link.open_newwindow", 3);
       options.addPreference("browser.link.open_newwindow.restriction", 0);
    pass firefox options as parameter to create driver
       WebDriver driver = new FirefoxDriver(options);
    

提交回复
热议问题