List of usage examples for org.openqa.selenium.firefox FirefoxProfile setPreference
public void setPreference(String key, Object value)
From source file:FirefoxConsoleExport.java
License:Open Source License
public FirefoxConsoleExport(int port) throws IOException { super(port);//from w ww .j a va 2 s. c o m start(NanoHTTPD.SOCKET_READ_TIMEOUT, false); ClassLoader classLoader = FirefoxConsoleExport.class.getClassLoader(); DesiredCapabilities cap = new DesiredCapabilities(); cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); FirefoxProfile fp = new FirefoxProfile(); File extensionToInstall = new File(classLoader.getResource("firebug-2.0.16-fx.xpi").getFile()); File extension2 = new File(classLoader.getResource("consoleExport-0.5b5.xpi").getFile()); fp.addExtension(extensionToInstall); fp.addExtension(extension2); fp.setPreference("extensions.firebug.currentVersion", "2.0"); fp.setPreference("extensions.firebug.console.enableSites", "true"); fp.setPreference("extensions.firebug.net.enableSites", "true"); fp.setPreference("extensions.firebug.script.enableSites", "true"); fp.setPreference("extensions.firebug.allPagesActivation", "on"); fp.setPreference("extensions.firebug.consoleexport.active", "true"); fp.setPreference("extensions.firebug.consoleexport.serverURL", "http://127.0.0.1:9999"); cap.setCapability(FirefoxDriver.PROFILE, fp); driver = new FirefoxDriver(cap); }
From source file:FormFiller.java
private static WebDriver getNewFirefoxDriver() { FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.download.folderList", 1); profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf"); profile.setPreference("pdfjs.disabled", true); profile.setPreference("plugin.scan.plid.all", false); profile.setPreference("plugin.scan.Acrobat", "90.0"); profile.setPreference("plugin.disable_full_page_plugin_for_types", "application/pdf"); return new FirefoxDriver(profile); }
From source file:ExperimentRunner.java
License:Apache License
private void setupFirefox() throws Exception { DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox(); FirefoxBinary binary = new FirefoxBinary(new File(firefoxBinary)); FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.cache.disk.enable", false); profile.setPreference("browser.cache.disk_cache_ssl", false); profile.setPreference("browser.cache.memory.enable", false); profile.setPreference("browser.cache.offline.capacity", 0); profile.setPreference("browser.cache.offline.enable", false); profile.setPreference("media.cache_size", 0); profile.setPreference("network.http.use-cache", false); //profile.setPreference("brwoser.dom.window.dump.enabled", true); driver = new FirefoxDriver(binary, profile, desiredCapabilities); driver.manage().timeouts().implicitlyWait(120, TimeUnit.SECONDS); }
From source file:GeneralCookieDriver.java
License:Open Source License
public WebDriver getWebDriver(Browser browser, boolean privateBrowsing) { if (browser.equals(Browser.CHROME)) { DesiredCapabilities capabilities = DesiredCapabilities.chrome(); if (privateBrowsing) { capabilities.setCapability("chrome.switches", Arrays.asList("--incognito")); }// w w w. j a v a 2 s . c o m System.setProperty("webdriver.chrome.driver", chromeDriverLocation); return new ChromeDriver(capabilities); } else if (browser.equals(Browser.FIREFOX)) { FirefoxProfile ffp = new FirefoxProfile(); if (privateBrowsing) { ffp.setPreference("browser.privatebrowsing.dont_prompt_on_enter", true); ffp.setPreference("browser.privatebrowsing.autostart", true); } DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability(FirefoxDriver.PROFILE, ffp); return new FirefoxDriver(capabilities); } else if (browser.equals(Browser.IE)) { System.setProperty("webdriver.ie.driver", ieDriverLocation); DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); if (privateBrowsing) { System.err.println("Launching into browsing mode is not supported in IE."); return null; } return new InternetExplorerDriver(); } else if (browser.equals(Browser.SAFARI)) { if (privateBrowsing) { System.out .println("WARNING: Selenium does not support launching into Safari private browsing mode."); System.out .println(" You will be given 10 seconds to transition into the private browsing "); System.out.println(" mode before the tests begin!"); } return new SafariDriver(); } return null; }
From source file:botski.selenium.SocialBot.java
License:Apache License
/** * Initialises Firefox as the default browser *///from w w w . j a v a2 s . c o m public void initializeFirefox() { FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("webdriver.load.strategy", "fast"); profile.setPreference("browser.tabs.loadInBackground", false); profile.setPreference("browser.tabs.warnOnClose", false); profile.setPreference("browser.tabs.warnOnOpen", false); if (proxyHost != null) { profile.setPreference("network.proxy.type", 1); profile.setPreference("network.proxy.http", proxyHost); profile.setPreference("network.proxy.http_port", proxyPort); profile.setPreference("network.proxy.ssl", proxyHost); profile.setPreference("network.proxy.ssl_port", proxyPort); } browser = new FirefoxDriver(profile); browser.manage().timeouts().pageLoadTimeout(timeout, TimeUnit.MILLISECONDS); browser.manage().timeouts().setScriptTimeout(timeout, TimeUnit.MILLISECONDS); browser.manage().timeouts().implicitlyWait(timeout, TimeUnit.MILLISECONDS); javascript = (JavascriptExecutor) browser; browser.manage().window().setSize(new Dimension(1024, 768)); }
From source file:br.ufmg.dcc.saotome.beholder.selenium.SeleniumController.java
License:Apache License
/** * This method starts the selenium remote control using the parameters * informed by testng.xml file//from w w w . ja va 2s.com * @param parameters * @throws Exception */ @BeforeSuite(alwaysRun = true) @Parameters(value = { "parameters" }) public static void startSelenium(String parameters) { parametersMap = parameterScanner(parameters); parametersInfo(); String browserName = parametersMap.get("browser"), profile = parametersMap.get("profile"), chromeDriverBin = parametersMap.get("chromeDriverBin"), ieDriverBin = parametersMap.get("ieDriverBin"), chromeBin = parametersMap.get("chromeBin"), languages = parametersMap.get("languages"); if (browserName == null) { throw new IllegalArgumentException( String.format(ErrorMessages.ERROR_TEMPLATE_VARIABLE_NULL, "browser")); } if (driver == null) { if (BrowsersList.FIREFOX.equalsString(browserName)) { FirefoxProfile fp = new FirefoxProfile(); fp.setPreference("dom.max_script_run_time", 0); fp.setPreference("dom.max_chrome_script_run_time", 0); if (profile != null && !profile.isEmpty()) { fp.setPreference("webdriver.firefox.profile", profile); } if (languages != null && !languages.isEmpty()) { fp.setPreference("intl.accept_languages", languages); } driver = new WebDriverAdapter(new FirefoxDriver(fp)); } else if (BrowsersList.CHROME.equalsString(browserName)) { if (chromeBin == null) { throw new IllegalArgumentException( String.format(ErrorMessages.ERROR_TEMPLATE_VARIABLE_NULL, "chromeBin")); } // Optional, if not specified, WebDriver will search your path for chromedriver // in the system environment. (OBS: To evade problems, webdriver.chrome.driver MUST have a value. if (System.getProperty("webdriver.chrome.driver") == null || System.getProperty("webdriver.chrome.driver").isEmpty()) { if (chromeDriverBin == null) { throw new IllegalArgumentException( String.format(ErrorMessages.ERROR_TEMPLATE_VARIABLE_NULL, "chromeDriverBin")); } System.setProperty("webdriver.chrome.driver", chromeDriverBin); } ChromeOptions co = new ChromeOptions(); // Get the chrome binary directory path from System Envionment. co.setBinary(new File(chromeBin)); driver = new WebDriverAdapter(new ChromeDriver(co)); } else if (BrowsersList.IE.equalsString(browserName)) { if (ieDriverBin == null) { throw new IllegalArgumentException( String.format(ErrorMessages.ERROR_TEMPLATE_VARIABLE_NULL, "ieDriverBin")); } System.setProperty("webdriver.ie.driver", ieDriverBin); driver = new WebDriverAdapter(new InternetExplorerDriver()); } else if (BrowsersList.HTML_UNIT.equalsString(browserName)) { driver = new HtmlUnitDriver(true); } else { throw new IllegalArgumentException(ErrorMessages.ERROR_BROWSER_INVALID); } } /* Sets to all driver methods the global timeout of 1 second. * To tests, Timeouts must be specified on the components. */ SeleniumController.driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS); SeleniumController.builder = new SeleniumBuilder(driver); SeleniumController.browser = new SeleniumBrowser(); ListenerGateway.setWebDriver(driver); ListenerGateway.setParameters(parametersMap); }
From source file:co.edu.icesi.i2t.slrtools.webdrivers.WebDriverIEEEXplore.java
License:Open Source License
/** * Funcion que se encarga de realizar automaticamente la busqueda en la base * de datos IEEEXplore conforme a una cadena de busqueda introducida, la * automatizacion nos permite descargar los CSV que IEEEXplore dispone con * el resultaod de las busquedas, la ruta donde se guardan los archivos * dependen de la seleccin del usuario, si por alguna razon el resultado de * la busqueda es mayor a 2000 datos, el buscador solo deja descargar los * primeros 2000 ordenados por importancia de acuerdo a las politicas de * IEEEXplore, los archivos descargados posteriormente son procesadas para * la construccion del BIB con los resultados obtenidos. * * @param searchStrings este parametro es la cadena de busqueda que retorna * la funcion mixIEEEXplore#mixWords, cada cadena de busqueda esta separada * por ;//ww w . j a v a 2s . c om * @param url este paremetro es el URL de la busqueda avanzada de IEEEXplore * @see mixWords.mixIEEEXplore#mixWords(java.lang.String, java.lang.String) */ public static void searchWeb(String searchStrings, String url) { System.out.println(""); System.out.println("-----------------------------"); System.out.println("Searching IEEE Xplore Digital Library..."); System.out.println("Search strings: " + searchStrings + ""); System.out.println(""); String workingDir = System.getProperty("user.dir"); File targetDirectory = new File("files" + File.separator + Database.IEEE_XPLORE.getName()); targetDirectory.mkdir(); FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.download.folderList", 2); profile.setPreference("browser.download.manager.showWhenStarting", false); profile.setPreference("browser.download.dir", workingDir + File.separator + "files" + File.separator + Database.IEEE_XPLORE.getName()); profile.setPreference("browser.download.useDownloadDir", true); profile.setPreference("browser.helperapps.neverAsk.saveToDisk", "application/x-latex;text/csv"); profile.setPreference("browser.helperApps.alwaysAsk.force", false); profile.setPreference("browser.download.manager.alertOnEXEOpen", false); profile.setPreference("browser.download.manager.closeWhenDone", true); WebDriver webDriver = new FirefoxDriver(profile); String[] strings = searchStrings.split(";"); for (int i = 0; i < strings.length; i++) { try { webDriver.get(url); WebElement searchField = webDriver.findElement(By.id("expression-textarea")); WebElement buttonSearch = webDriver.findElement(By.id("submit-search")); try { Thread.sleep(1000); } catch (InterruptedException e) { } searchField.click(); searchField.sendKeys(strings[i]); try { Thread.sleep(1000); } catch (InterruptedException e) { } buttonSearch.click(); try { WebElement exportField = (new WebDriverWait(webDriver, 10)) .until(ExpectedConditions.presenceOfElementLocated(By.id("popup-export-results"))); WebElement stringResult = webDriver .findElement(By.xpath("//div[contains(@id, 'content')]/span")); try { Thread.sleep(1000); } catch (InterruptedException e) { } exportField.click(); System.out.println("[INFO] Search string " + (i + 1) + " " + strings[i] + " " + stringResult.getText()); WebElement exportButton = (new WebDriverWait(webDriver, 10)) .until(ExpectedConditions.presenceOfElementLocated(By.id("export_results_ok"))); exportButton.click(); } catch (Exception e) { System.out.println( "[WARNING] Search string " + (i + 1) + " " + strings[i] + " retrieves no results"); } } catch (Exception e) { System.out.println( "[ERROR] Search string " + (i + 1) + " " + strings[i] + " failed. " + e.getMessage()); } try { Thread.sleep(5000); } catch (InterruptedException e) { } } // webDriver.quit(); System.out.println("[INFO] Finished search in IEEE Xplore Digital Library"); System.out.println("-----------------------------"); }
From source file:co.edu.icesi.i2t.slrtools.webdrivers.WebDriverScienceDirect.java
License:Open Source License
/** * Funcion que se encarga de realizar automaticamente la busqueda en la base * de datos ScienceDirect conforme a una cadena de busqueda introducida, la * automatizacion nos permite descargar los BIB que ScienceDirect dispone * con el resultaod de las busquedas, la ruta donde se guardan losr archivos * dependen de la seleccin del usuario, si por alguna razon el resultado de * la busqueda es mayor a 1000 datos, el buscador solo deja descargar los * primeros 1000 ordenados por importancia de acuerdo a las politicas de * ScienceDirect, los archivos descargados posteriormente son procesadas * para la construccion del BIB consolodidado con los resultados obtenidos. * * @param searchStrings este parametro es la cadena de busqueda que retorna * la funcion mixScienceDirect#mixWords, cada cadena de busqueda esta * separada por ;// w w w. jav a2 s . c o m * @param url este paremetro es el URL de la busqueda experta de * ScienceDirect * @see mixWords.mixScienceDirect#mixWords(java.lang.String, * java.lang.String) */ public static void searchWeb(String searchStrings, String url) { System.out.println(""); System.out.println("-----------------------------"); System.out.println("Searching Science Direct..."); System.out.println("Search strings: " + searchStrings + ""); System.out.println(""); String workingDir = System.getProperty("user.dir"); File targetDirectory = new File("files" + File.separator + Database.SCIENCE_DIRECT.getName()); targetDirectory.mkdir(); FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.download.folderList", 2); profile.setPreference("browser.download.manager.showWhenStarting", false); profile.setPreference("browser.download.dir", workingDir + File.separator + "files" + File.separator + Database.SCIENCE_DIRECT.getName()); profile.setPreference("browser.download.useDownloadDir", true); profile.setPreference("browser.helperapps.neverAsk.saveToDisk", "application/x-latex;text/csv"); profile.setPreference("browser.helperApps.alwaysAsk.force", false); profile.setPreference("browser.download.manager.alertOnEXEOpen", false); profile.setPreference("browser.download.manager.closeWhenDone", true); profile.setPreference("browser.download.panel.shown", true); WebDriver webDriver = new FirefoxDriver(profile); String[] strings = searchStrings.split(";"); for (int i = 0; i < strings.length; i++) { try { webDriver.get(url); WebElement searchField = webDriver.findElement(By.name("SearchText")); // WebElement searchField = (new WebDriverWait(webDriver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.name("SearchText"))); WebElement submitSearch = webDriver.findElement(By.name("RegularSearch")); // WebElement submitSearch = (new WebDriverWait(webDriver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.name("RegularSearch"))); try { Thread.sleep(10000); } catch (InterruptedException e) { } searchField.click(); searchField.sendKeys(strings[i]); try { Thread.sleep(10000); } catch (InterruptedException e) { } submitSearch.click(); try { WebElement exportButton = (new WebDriverWait(webDriver, 10)).until(ExpectedConditions .presenceOfElementLocated(By.cssSelector("span.down_sci_dir.exportArrow"))); WebElement stringResult = webDriver .findElement(By.xpath("//h1[contains(@class, 'queryText')]/strong")); try { Thread.sleep(10000); } catch (InterruptedException e) { } exportButton.click(); System.out.println("[INFO] Search string " + (i + 1) + " " + strings[i] + " " + stringResult.getText()); WebElement bibTex = webDriver.findElement(By.id("BIBTEX")); bibTex.click(); WebElement export = webDriver.findElement(By.id("export_button")); export.click(); } catch (Exception e) { System.out.println( "[WARNING] Search string " + (i + 1) + " " + strings[i] + " retrieves no results"); } } catch (Exception e) { System.out.println( "[ERROR] Search string " + (i + 1) + " " + strings[i] + " failed. " + e.getMessage()); } try { Thread.sleep(5000); } catch (InterruptedException e) { } } // webDriver.quit(); System.out.println("[INFO] Finished search in Science Direct"); System.out.println("-----------------------------"); }
From source file:co.edu.icesi.i2t.slrtools.webdrivers.WebDriverSpringerLink.java
License:Open Source License
/** * Funcion que se encarga de realizar automaticamente la busqueda en la base * de datos SpringerLink conforme a una cadena de busqueda introducida, la * automatizacion nos permite descargar los CSV que SpringerLink dispone con * el resultaod de las busquedas, la ruta donde se guardan losr archivos * dependen de la seleccin del usuario, si por alguna razon el resultado de * la busqueda es mayor a 1000 datos, el buscador solo deja descargar los * primeros 1000 ordenados por importancia de acuerdo a las politicas de * SpringerLink, los archivos descargados posteriormente son procesadas para * la construccion del BIB consolodidado con los resultados obtenidos. * * @param searchStrings este parametro es la cadena de busqueda que retorna * la funcion mixScienceDirect#mixWords, cada cadena de busqueda esta * separada por ;/*from ww w .j a v a 2s. co m*/ * @param url este paremetro es el URL de la busqueda experta de * ScienceDirect, el url es incompleto y se complementa con la informacion * del primer parametro * @see mixWords.mixSpringer#mixWords(java.lang.String, java.lang.String) */ public static void searchWeb(String searchStrings, String url) { /* a esta funcion se debe mejorar * 1: automatizar las preferencias para la descarga automatica * 2: la ruta de descarga * 3: el cierre del navegador al finalizar la ultima descarga*/ System.out.println(""); System.out.println("-----------------------------"); System.out.println("Searching Springer Link..."); System.out.println("Search strings: " + searchStrings); System.out.println(""); FirefoxProfile profile = new FirefoxProfile(); String workingDir = System.getProperty("user.dir"); File targetDirectory = new File("files" + File.separator + Database.SPRINGER_LINK.getName()); targetDirectory.mkdir(); profile.setPreference("browser.download.folderList", 2); profile.setPreference("browser.download.manager.showWhenStarting", false); profile.setPreference("browser.download.dir", workingDir + File.separator + "files" + File.separator + Database.SPRINGER_LINK.getName()); profile.setPreference("browser.download.useDownloadDir", true); profile.setPreference("browser.helperapps.neverAsk.saveToDisk", "application/x-latex;text/csv"); profile.setPreference("browser.helperApps.alwaysAsk.force", false); profile.setPreference("browser.download.manager.alertOnEXEOpen", false); profile.setPreference("browser.download.manager.closeWhenDone", true); WebDriver webDriver = new FirefoxDriver(profile); String[] strings = searchStrings.split(";"); for (int i = 0; i < strings.length; i++) { try { webDriver.get(url + strings[i]); //WebElement searchField = url.findElement(By.name("title-is")); //WebElement buttonSearch = url.findElement(By.id("submit-advanced-search")); //searchField.click(); //searchField.sendKeys(lcadenasBusqueda[i]); //buttonSearch.click(); try { WebElement exportField = (new WebDriverWait(webDriver, 10)).until(ExpectedConditions .presenceOfElementLocated(By.cssSelector("#tool-download > span.icon"))); WebElement stringResult = webDriver.findElement( By.xpath("//h1[contains(@class, 'number-of-search-results-and-search-terms')]/strong")); System.out.println("[INFO] Search string " + (i + 1) + " " + strings[i] + " has " + stringResult.getText() + " result(s) returned"); try { Thread.sleep(2000); } catch (InterruptedException e) { } exportField.click(); } catch (Exception e) { System.out.println( "[WARNING] Search string " + (i + 1) + " " + strings[i] + " retrieves no results"); } } catch (Exception e) { System.out.println( "[ERROR] Search string " + (i + 1) + " " + strings[i] + " failed. " + e.getMessage()); } } // webDriver.quit(); System.out.println("[INFO] Finished search in Springer Link"); System.out.println("-----------------------------"); }
From source file:com.axatrikx.webdriver.FirefoxLoader.java
License:Apache License
@Override public WebDriver getDriver() { WebDriver driver;//from ww w. j a va 2 s . co m FirefoxProfile profile; if (!firefoxProfile.isEmpty()) { ProfilesIni allProfiles = new ProfilesIni(); try { profile = allProfiles.getProfile(firefoxProfile); } catch (Exception e) { profile = new FirefoxProfile(); } } else { profile = new FirefoxProfile(); } profile.setPreference("browser.download.dir", downloadDir); profile.setPreference("browser.download.folderList", 2); if (useProxy) { profile.setPreference("network.proxy.type", 1); profile.setPreference("network.proxy.http", proxyHost); profile.setPreference("network.proxy.http_port", proxyPort); profile.setPreference("network.proxy.ssl", proxyHost); profile.setPreference("network.proxy.ssl_port", proxyPort); profile.setPreference("network.proxy.ftp", proxyHost); profile.setPreference("network.proxy.ftp_port", proxyPort); } else { profile.setPreference("network.proxy.type", Proxy.ProxyType.AUTODETECT.ordinal()); } if (!firefoxBinaryPath.isEmpty()) { // set custom firefox binary FirefoxBinary binary = new FirefoxBinary(new File(firefoxBinaryPath)); driver = new FirefoxDriver(binary, profile); } else { driver = new FirefoxDriver(profile); } return driver; }