Best Selenium code snippet using org.openqa.selenium.firefox.FirefoxProfile.setPreference
Source:Demo02.java
...19// FirefoxDriver driver = new FirefoxDriver(prof.getProfile("default"));20 21 //ä¿®æ¹é¦é¡µé»è®¤ç½å22// FirefoxProfile profile = new FirefoxProfile();23// profile.setPreference("browser.startup.homepage","http://www.huicewang.com/ecshop"); 24// profile.setPreference("browser.startup.page","1");25 //设置æµè§å¨ä»£ç26// // 使ç¨ä»£ç27// FirefoxProfile profile = new FirefoxProfile();28// profile.setPreference("network.proxy.type", 1);29// // httpå议代çé
ç½®30// profile.setPreference("network.proxy.http", "127.0.0.1"); 31// profile.setPreference("network.proxy.http_port", 8888);32// profile.setPreference("network.proxy.ssl", "127.0.0.1"); 33// profile.setPreference("network.proxy.ssl_port", 443); 34// // ææåè®®å
¬ç¨ä¸ç§ä»£çé
ç½®ï¼å¦æåç¬é
ç½®ï¼è¿é¡¹è®¾ç½®ä¸ºfalse35// profile.setPreference("network.proxy.share_proxy_settings", true); 36// // 对äºlocalhostçä¸ç¨ä»£çï¼è¿éå¿
é¡»è¦é
ç½®ï¼å¦åæ æ³åwebdriveré讯37// profile.setPreference("network.proxy.no_proxies_on", "127.0.0.1");38 39 40 //æ æ示é»è®¤è·¯å¾ä¸è½½41// FirefoxProfile profile = new FirefoxProfile();42// profile.setPreference("browser.download.dir", "d:\\"); 43//// 设置Firefoxçé»è®¤ ä¸è½½ æ件夹 0æ¯æ¡é¢ï¼1æ¯âæçä¸è½½âï¼2æ¯èªå®ä¹44// profile.setPreference("browser.download.folderList", 2); 45// profile.setPreference("browser.download.manager.showWhenStarting", false);46// profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream, application/vnd.ms-excel, text/csv, application/zip");47// FirefoxDriver driver = new FirefoxDriver(profile);48// driver.get("http://storage.360buyimg.com/jdmobile/JDMALL-PC2.apk");49 50// //èªå¨æ¶é页é¢å è½½æ¶åºå¾51 FirefoxProfile profile = new FirefoxProfile();52 profile.addExtension(new File("source\\firebug-2.0.17.xpi"));53 profile.addExtension(new File("source\\netExport-0.8.xpi"));54 55 profile.setPreference("extensions.firebug.allPagesActivation", "on");56 profile.setPreference("extensions.firebug.net.enableSites", "true");57 profile.setPreference("extensions.firebug.defaultPanelName", "net");58 profile.setPreference("extensions.firebug.netexport.alwaysEnableAutoExport", "true");59 profile.setPreference("extensions.firebug.netexport.saveFiles", "true");60 profile.setPreference("extensions.firebug.netexport.defaultLogDir", "d:\\");61 FirefoxDriver driver = new FirefoxDriver(profile);62 Thread.sleep(2000);63 driver.get("http://www.huicewang.com");64 driver.get("http://www.baidu.com");65 66 }67}
Source:TestSeleniumFirefox.java
...21 FirefoxOptions options = new FirefoxOptions();22 FirefoxProfile profile = new FirefoxProfile(new File("C:\\Users\\Xiaomi\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\p15"));23 //ProfilesIni listProfiles = new ProfilesIni();24 //FirefoxProfile profile = listProfiles.getProfile("p15");25 //profile.setPreference("webdriver.load.strategy", "unstable");26 //profile.setAssumeUntrustedCertificateIssuer(false);27 //profile.setPreference("browser.download.dir", "C:\\download");28 //profile.setPreference("browser.download.folderList", 2);//profile.setPreference("webdriver.firefox.profile", "p15");29 //System.out.println(profile);30 //options.setProfile(profile);31 options.addArguments("-P", "p15");32 options.addArguments("-new-instance");33 //options.addPreference("webdriver.firefox.profile", "p15");34 //options.addPreference("-P", "C:\\Users\\Xiaomi\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\p15")35// FirefoxProfile firefoxProfile = new FirefoxProfile();36// firefoxProfile.setPreference("browser.download.folderList",2); //dont take default download folder37// firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false);//dont show download box38// firefoxProfile.setPreference("browser.download.dir","c:\\downloads");//provide download location39// firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv"); //dont ask save as for provided types40// options.setProfile(firefoxProfile);41 ;42 //options.addArguments("--headless");43 //options.addArguments("--disable-gpu");44 //options.addArguments("--user-data-dir=profile3");45 WebDriver driver = new FirefoxDriver(options);46 System.out.println("created");47 driver.get("https://2ip.ru/");48 System.out.println("wait");49 new WebDriverWait(driver, 100).until(50 webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));51 System.out.println("done");52 String text =53 driver.findElement(By.id("d_clip_button"))...
Source:DriversConfig.java
...18 FirefoxBinary firefoxBinary = new FirefoxBinary();19 firefoxBinary.addCommandLineOptions("--headless");20 System.setProperty("webdriver.gecko.driver", "./geckodriver");21 FirefoxProfile firefoxProfile = new FirefoxProfile();22 firefoxProfile.setPreference("dom.webnotifications.enabled", false);23 FirefoxOptions firefoxOptions = new FirefoxOptions();24 firefoxOptions.setBinary(firefoxBinary);25 firefoxOptions.setProfile(firefoxProfile);26 FirefoxDriver firefoxDriver = new FirefoxDriver(firefoxOptions);27 return firefoxDriver;28 } else {29 System.setProperty("webdriver.gecko.driver", "./geckodriver");30 FirefoxDriver firefoxDriver = new FirefoxDriver();31 return firefoxDriver;32 }33 }34 //Instance a chrome driver35 public static ChromeDriver headlessOrNot(String headless, String chromePath)36 {37 if (headless.equals("true")) {38 ChromeOptions chromeOptions = new ChromeOptions();39 chromeOptions.setBinary(chromePath);40 chromeOptions.addArguments("--headless");41 System.setProperty("webdriver.chrome.driver", "./chromedriver");42 ChromeDriver chromeDriver = new ChromeDriver(chromeOptions);43 return chromeDriver;44 } else {45 System.setProperty("webdriver.chrome.driver", "./chromedriver");46 ChromeDriver chromeDriver = new ChromeDriver();47 return chromeDriver;48 }49 }50 //Instance a firefox driver that hides the pop up that shows up when trying to download51 public static FirefoxDriver noDownloadPopUp(String headless, String folder)52 {53 System.setProperty("webdriver.gecko.driver", "./geckodriver");54 FirefoxProfile firefoxProfile = new FirefoxProfile();55 firefoxProfile.setPreference("browser.download.folderList", 2);56 firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);57 firefoxProfile.setPreference("browser.download.dir", System.getProperty("user.dir") + File.separator + folder);58 firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "text/csv;audio/wav;audio/vnd.wave;audio/wave;audio/x-wav");59 FirefoxOptions firefoxOptions = new FirefoxOptions();60 if (headless.equals("true")) {61 FirefoxBinary firefoxBinary = new FirefoxBinary();62 firefoxBinary.addCommandLineOptions("--headless");63 firefoxOptions.setBinary(firefoxBinary);64 }65 firefoxOptions.setProfile(firefoxProfile);66 FirefoxDriver firefoxDriver = new FirefoxDriver(firefoxOptions);67 return firefoxDriver;68 }69}...
Source:Firefox.java
...42 }43 @Test44 public void runWithCustomProfile() throws InterruptedException{45 FirefoxProfile profile = new FirefoxProfile();46 profile.setPreference("intl.accept_languages", "en-us, en");47 profile.setPreference("browser.download.dir","C:/temp");48 profile.setPreference("browser.download.folderList", 2);49 50 profile.setAssumeUntrustedCertificateIssuer(false);51 profile.setAcceptUntrustedCertificates(true);52 53 FirefoxDriver driver = new FirefoxDriver(profile);54 driver.get("http://ci.seleniumhq.org:8080/");55 Thread.sleep(2000);56 57 System.out.println(driver.getTitle());58 driver.quit();59 }60 @Test61 public void runWithExtensions() throws IOException{62 63 FirefoxProfile profile = new FirefoxProfile();64 profile.addExtension(new File("C:/auto_tools/firebug@software.joehewitt.com.xpi"));65 profile.setPreference("extensions.firebug.currentVersion", "8.8.8");66 profile.setPreference("extensions.firebug.allPagesActivation", "on");67 profile.setPreference("extensions.firebug.defaultPanelName", "net");68 69 FirefoxDriver driver = new FirefoxDriver(profile);70 driver.get("http://google.com");71 }72 @Test73 public void runWithExistingProfile(){74 75 FirefoxProfile profile = new FirefoxProfile(new File("C:/Users/R_O_Y/AppData/Roaming/Mozilla/Firefox/Profiles/70qlsh9s.Selenium"));76 77 78 FirefoxDriver driver = new FirefoxDriver(profile);79 driver.get("http://facebook.com");80 }81 @Test...
Source:Firefox_OptionsExample.java
...46 // tell selenium to launch mod -1147 ProfilesIni allProf = new ProfilesIni();// all profiles on pc48 FirefoxProfile prof = allProf.getProfile("testProfile");49 // notifications50 prof.setPreference("dom.webnotifications.enabled", false);// turn off51 // certificate52 prof.setAcceptUntrustedCertificates(true);53 prof.setAssumeUntrustedCertificateIssuer(false);54 55 //proxy servers56/* prof.setPreference("network.proxy.type", 1);57 prof.setPreference("network.proxy.socks", "83.209.94.87");58 prof.setPreference("network.proxy.socks_port", 35923);59 60 options.setProfile(prof);*/61 62 63 WebDriver driver = new FirefoxDriver(options);// launching browser64 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);65 try {66 Thread.sleep(5000l);67 } catch (InterruptedException e) {68 // TODO Auto-generated catch block69 e.printStackTrace();70 }71 driver.get("https://www.google.com");72
...
Source:DownloadSettingsTest2.java
...14 // # 0 means to download to the desktop, 1 means to download to the15 // default "Downloads" directory, 2 means to use the directory you16 // specify in "browser.download.dir", 2 below17 // download window18 firefoxProfile.setPreference("browser.download.folderList", 2);19 firefoxProfile.setPreference("browser.download.manager.showWhenStarting", false);20 //// firefox about:config21 firefoxProfile.setPreference("browser.download.dir", "C:\\Users\\TimeMachine\\Desktop");22 // allowed extension23 firefoxProfile.setPreference("browser.helperApps.neverAsk.openFile",24 "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");25 // dont ask for these exten26 firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk",27 "text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");28 firefoxProfile.setPreference("browser.helperApps.alwaysAsk.force", false);29 firefoxProfile.setPreference("browser.download.manager.alertOnEXEOpen", false);30 firefoxProfile.setPreference("browser.download.manager.focusWhenStarting", false);31 firefoxProfile.setPreference("browser.download.manager.useWindow", false);32 firefoxProfile.setPreference("browser.download.manager.showAlertOnComplete", false);33 firefoxProfile.setPreference("browser.download.manager.closeWhenDone", false);34 // Create Options object to load preferences35 FirefoxOptions options = new FirefoxOptions();36 // add profile to Options37 options.setProfile(firefoxProfile);38 // create driver with FirefoxDriver - use Constructor with Options39 WebDriver driver = new FirefoxDriver(options);40 driver.get("https://mdcune.psych.ucla.edu/modules/bioinformatics/extras/QTL_Sample_data.xls/view");41 driver.findElement(By.xpath("//a[@href='https://mdcune.psych.ucla.edu/modules/bioinformatics/extras/QTL_Sample_data.xls/at_download/file']")).click();42 }43}...
Source:BrowserFactory.java
...24 }25 case "FIREFOX" -> {26 FirefoxOptions firefoxOptions = new FirefoxOptions();27 FirefoxProfile firefoxProfile = new FirefoxProfile();28 firefoxProfile.setPreference("browser.download.folderList", 2);29 firefoxProfile.setPreference("browser.download.dir",userDir + "\\" + configLoader.getProperty("downloadPath"));30 firefoxProfile.setPreference("browser.helperApps.neverAsk.openFile", "application/octet-stream");31 firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream");32 firefoxOptions.setProfile(firefoxProfile);33 System.setProperty("webdriver.gecko.driver", "src/test/resources/drivers/geckodriver.exe");34 driver = new FirefoxDriver(firefoxOptions);35 }36 default -> {37 return null;38 }39 }40 return driver;41 }42}...
Source:OptionsManager.java
...14 FirefoxOptions firefoxOptions = new FirefoxOptions();15 FirefoxProfile firefoxProfile = new FirefoxProfile();16 firefoxProfile.setAcceptUntrustedCertificates(true);17 firefoxProfile.setAssumeUntrustedCertificateIssuer(false);18 firefoxProfile.setPreference("geo.enabled", true);19 firefoxProfile.setPreference("geo.prompt.testing", true);20 firefoxProfile.setPreference("geo.prompt.testing.allow", true);21 firefoxOptions.setCapability(FirefoxDriver.PROFILE, firefoxProfile);22 return firefoxOptions;23 }24}...
setPreference
Using AI Code Generation
1FirefoxProfile profile = new FirefoxProfile();2profile.setPreference("network.proxy.type", 1);3profile.setPreference("network.proxy.http", "localhost");4profile.setPreference("network.proxy.http_port", 8080);5profile.setPreference("network.proxy.ssl", "localhost");6profile.setPreference("network.proxy.ssl_port", 8080);7profile.setPreference("network.proxy.ftp", "localhost");8profile.setPreference("network.proxy.ftp_port", 8080);9profile.setPreference("network.proxy.socks", "localhost");10profile.setPreference("network.proxy.socks_port", 8080);11profile.setPreference("network.proxy.share_proxy_settings", true);12profile.setPreference("network.proxy.no_proxies_on", "localhost");13profile.setPreference("network.proxy.autoconfig_url.include_path", true);14profile.setPreference("network.proxy.autoconfig_retry", 5);15profile.setPreference("network.proxy.failover_timeout", 5);16WebDriver driver = new FirefoxDriver(profile);17FirefoxProfile profile = new FirefoxProfile();18Proxy proxy = new Proxy();19proxy.setProxyType(Proxy.ProxyType.MANUAL);20proxy.setHttpProxy("localhost:8080");21proxy.setSslProxy("localhost:8080");22profile.setProxyPreferences(proxy);23WebDriver driver = new FirefoxDriver(profile);24ChromeOptions options = new ChromeOptions();25WebDriver driver = new ChromeDriver(options);26DesiredCapabilities capabilities = new DesiredCapabilities();27Proxy proxy = new Proxy();28proxy.setProxyType(Proxy.ProxyType.MANUAL);29proxy.setHttpProxy("localhost:8080");30proxy.setSslProxy("localhost:8080");31capabilities.setCapability(CapabilityType.PROXY, proxy);32WebDriver driver = new FirefoxDriver(capabilities);33DesiredCapabilities capabilities = new DesiredCapabilities();34capabilities.setCapability("proxy", ProxyHelper.getProxy());35WebDriver driver = new FirefoxDriver(capabilities);
setPreference
Using AI Code Generation
1package com.automation.selenium.webDriver;2import org.openqa.selenium.By;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.firefox.FirefoxDriver;5import org.openqa.selenium.firefox.FirefoxProfile;6import org.openqa.selenium.support.ui.ExpectedConditions;7import org.openqa.selenium.support.ui.WebDriverWait;8public class Example1 {9public static void main(String[] args) {10String path = "C:\\Users\\Administrator\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\y6xh5h5n.default";11FirefoxProfile profile = new FirefoxProfile();12profile.setPreference("browser.download.dir", "C:\\Users\\Administrator\\Desktop\\Selenium");13profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;");14profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/pdf");15profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/octet-stream");16WebDriver driver = new FirefoxDriver(profile);17driver.findElement(By.linkText("2.47.1")).click();18WebDriverWait wait = new WebDriverWait(driver, 10);19wait.until(ExpectedConditions.titleIs("Selenium - Web Browser Automation"));20driver.quit();21}22}
LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.
Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.
What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.
Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.
Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.
How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.
Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.
Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.
LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!