List of usage examples for org.openqa.selenium.support.ui WebDriverWait WebDriverWait
public WebDriverWait(WebDriver driver, Duration timeout)
From source file:co.edu.icesi.i2t.slrtools.webdrivers.WebDriverACM.java
License:Open Source License
/** * Funcion que se encarga de realizar automaticamente la busqueda en la base * de datos ACM Digital Library conforme a una cadena de busqueda * introducida, ACM digital library no permite la descarga de ningun archivo * del resultado de la busqueda, por tal razn, se descarga el codigo fuente * de la pagina en el source del proyecto el cual posteriormente es usado * para la extraccin de la informacin y construccion del BIB con los * resultados obtenidos//from www . ja v a2 s. c o m * * @param searchStrings este parametro es la cadena de busqueda que retorna * la funcion mixACM#mixWords2, cada cadena de busqueda esta separada por ; * @param url este paremetro es el URL de la busqueda avanzada de ACM * Digital Library * @see mixWords.mixACM#mixWords2(java.lang.String, java.lang.String) */ public static void searchWeb(String searchStrings, String url) { /* a esta funcion se debe mejorar * 1: validar el boton siguiente sin try catch, mejorar el manejo de las expeciones */ System.out.println(""); System.out.println("-----------------------------"); System.out.println("Searching ACM Digital Library..."); System.out.println("Search strings: " + searchStrings + ""); System.out.println(""); FirefoxProfile profile = new FirefoxProfile(); 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("within")); searchField.click(); searchField.sendKeys(strings[i]); WebElement buttonSearch = webDriver.findElement(By.name("Go")); buttonSearch.click(); List<WebElement> stringResult = webDriver .findElements(By.xpath("//span[contains(@style, 'background-color:yellow')]")); if (!stringResult.isEmpty()) { System.out.println( "[WARNING] Search string " + (i + 1) + ": " + strings[i] + " retrieves no results"); } else { int counter = 1; try { WebElement nextField = null; do { String sourceCode = webDriver.getPageSource(); File targetDirectory = new File("files" + File.separator + Database.ACM.getName()); targetDirectory.mkdir(); try (PrintWriter file = new PrintWriter( "files" + File.separator + Database.ACM.getName() + File.separator + "searchResults_" + i + "_" + counter + ".html", "UTF-8")) { file.print(sourceCode); } nextField = (new WebDriverWait(webDriver, 10)) .until(ExpectedConditions.presenceOfElementLocated(By.linkText("next"))); try { Thread.sleep(10000); } catch (InterruptedException e) { } nextField.click(); counter++; } while (true); } catch (NoSuchElementException | TimeoutException | NullPointerException e) { System.out.println("[INFO] Search string " + (i + 1) + ": " + strings[i] + " has " + counter + (counter == 1 ? " result" : " results") + "returned"); } } } catch (FileNotFoundException | UnsupportedEncodingException e) { System.out.println( "[ERROR] Search string " + (i + 1) + ": " + strings[i] + " failed. " + e.getMessage()); } catch (NoSuchElementException e) { System.out.println( "[ERROR] The application has been blocked by ACM Digital Library. Try again later."); } try { Thread.sleep(10000); } catch (InterruptedException e) { } } webDriver.quit(); System.out.println("[INFO] Finished search in ACM Digital Library"); System.out.println("-----------------------------"); }
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 ;//from w w w. j a v a 2 s . c o m * @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. j av a 2s . com*/ * @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 w ww . j av 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:co.flexmod.selenium.example.integration.framework.WaitUtil.java
License:Apache License
/** * Waits for an jQuery AJAX call to be complete. * * @param driver//from ww w . j a v a 2s . c o m */ public static void waitForAjax(WebDriver driver) { WebDriverWait wait = new WebDriverWait(driver, 10); wait.until(new AjaxWait()); }
From source file:cochrane343.journal.test.JournalStepDefinitions.java
License:Open Source License
private WebElement waitFor(final String text) { final String xPath = String.format("//*[@text = '%s' or @content-desc='%s']", text, text); final By by = By.xpath(xPath); final ExpectedCondition<WebElement> presenceCondition = ExpectedConditions.presenceOfElementLocated(by); final WebDriverWait driverWait = new WebDriverWait(driver, WAIT_FOR_ELEMENT_TIMEOUT); driverWait.until(presenceCondition); return driver.findElement(by); }
From source file:com.actian.amc.pages.NewCloudDefinitionPage.java
private String getToolTipText() { driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); List<WebElement> WarningLink = driver.findElements(warningLink); //(By.cssSelector("img[class='gwt-Image']")); wait = new WebDriverWait(driver, 20); mouseHoverJScript(WarningLink.get(0)); wait.until(ExpectedConditions.visibilityOfElementLocated(tooltip)); String toolTipText = driver.findElement(tooltip).getText(); System.out.println("Tooltip/ Help message is " + toolTipText); return (toolTipText); }
From source file:com.adasasistemas.pilot.webtest3.NewSeleneseIT.java
@Test public void testSimple() throws Exception { // Create a new instance of the Firefox driver // Notice that the remainder of the code relies on the interface, // not the implementation. FirefoxProfile fp = new FirefoxProfile(); // fp.setPreference("browser.startup.homepage", URL); // fp.setPreference("startup.homepage_welcome_url", URL); //fp.setPreference("startup.homepage_welcome_url.additional", URL); FirefoxBinary fb = new FirefoxBinary(new File(NAVIGATOR)); WebDriver driver = new FirefoxDriver(fb, fp); // And now use this to visit NetBeans // driver.get("http://www.netbeans.org"); // Alternatively the same thing can be done like this // driver.navigate().to("http://www.netbeans.org"); // Check the title of the page // Wait for the page to load, timeout after 10 seconds driver.navigate().to("http://localhost:8085/webtest3"); //* driver.navigate().refresh(); // driver.get("http://localhost:8085/webtest3"); // System.out.println(driver.getPageSource()); (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { @Override/* w w w. j a va 2s .com*/ public Boolean apply(WebDriver d) { System.out.println(d.getPageSource()); return d.getPageSource().contains("Hello"); } }); //Close the browser driver.quit(); }
From source file:com.amazon.alexa.avs.AVSApp.java
License:Open Source License
/** * Performs amazon LWA login using the given <tt>driver</tt>. * //from w ww . ja va 2s .co m * @param driver Driver which is already configured to LWA login page. */ private void authenticate(final WebDriver driver) { log.debug("Title : {}", driver.getTitle()); new WebDriverWait(driver, 1000) .until(ExpectedConditions.and(ExpectedConditions.presenceOfElementLocated(By.id("ap_email")), ExpectedConditions.presenceOfElementLocated(By.id("ap_password")))); log.info("Auto logging in to LWA"); final WebElement username = driver.findElement(By.id("ap_email")); final WebElement password = driver.findElement(By.id("ap_password")); username.sendKeys(deviceConfig.getLWAUsername()); password.sendKeys(deviceConfig.getLWAPassword()); final WebElement button = driver.findElement(By.tagName("button")); button.click(); }
From source file:com.amolik.scrapers.OdishaRationCardScraper.java
public static void waitForBlock(WebDriver driver, String districtValue, String blockText) { By byText = By.xpath// w w w . ja v a 2s . c o m // ("//select["+ // "[@id='ddlDistrict']/option[@value='"+districtValue+"']"+ // " and "+ // " [@id='ddlBlock']/option[text()='"+blockText+"']"+ // "]"); ("//select[@id='ddlBlock']/option[text()='" + blockText + "']"); if (logger.isDebugEnabled()) { logger.debug("waitForBlock(" + "WebDriver, String, String) - xpath by string=" + byText.toString()); //$NON-NLS-1$ } WebElement element = new WebDriverWait(driver, 20) .until(ExpectedConditions.presenceOfElementLocated(byText)); }