List of usage examples for org.openqa.selenium.support.ui WebDriverWait WebDriverWait
public WebDriverWait(WebDriver driver, Duration timeout)
From source file:ca.nrc.cadc.UserStorageBrowserPage.java
License:Open Source License
public boolean isJqiColourMsgShowing(String message) { try {/* w w w .ja va2 s .c o m*/ WebElement jqiMsg = (new WebDriverWait(driver, 10)).until(ExpectedConditions.elementToBeClickable( xpath("//div[contains(@class, 'jqimessage')]/span[contains(text(), '" + message + "')]"))); return true; } catch (Exception e) { return false; } }
From source file:ca.nrc.cadc.web.selenium.AbstractTestWebPage.java
License:Open Source License
public AbstractTestWebPage(final WebDriver driver, final int timeoutInSeconds) { this.driver = driver; this.wait = new WebDriverWait(driver, DEFAULT_TIMEOUT_IN_SECONDS); this.timeoutInSeconds = timeoutInSeconds; }
From source file:ca.nrc.cadc.web.selenium.AbstractWebApplicationIntegrationTest.java
License:Open Source License
public <V> V waitUntil(final ExpectedCondition<V> expectedCondition) throws Exception { final WebDriverWait webDriverWait = new WebDriverWait(driver, TIMEOUT_IN_SECONDS); return webDriverWait.until(expectedCondition); }
From source file:ca.pe.cjsigouin.testinator.selenium.WebDriverMain.java
public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "/home/krystofurr/Programs/selenium/geckodriver"); System.setProperty("webdriver.chrome.driver", "/home/krystofurr/Programs/selenium/chromedriver"); // WebDriver driver = new FirefoxDriver(); WebDriver driver = new ChromeDriver(); // WebDriver driver = new InternetExplorerDriver(); //Puts an Implicit wait, Will wait for 10 seconds before throwing exception driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); //Launch website driver.navigate().to(CommonConstants.HOST + CommonConstants.URL_LOGIN); driver.findElement(By.id("emailAddress")).sendKeys("cjsigouin@gov.pe.ca"); driver.findElement(By.id("password")).sendKeys("Test12345!"); driver.findElement(By.id("loginButton")).click(); WebDriverWait wait = new WebDriverWait(driver, 5); wait.until(// w ww .ja v a 2 s .c o m ExpectedConditions.elementToBeClickable(By.xpath(".//*[@id='serviceWellSection']/div[2]/div/a/b"))); driver.get(CommonConstants.HOST + CommonConstants.URL_RESERVE_NAME_INTRO); WebDriverWait wait2 = new WebDriverWait(driver, 5); wait2.until(ExpectedConditions.elementToBeClickable(By.xpath(ReserveNameElement.INTRO_BUTTON_CANCEL))); driver.findElement(By.xpath(ReserveNameElement.INTRO_RADIO_RESERVE_NAME)).click(); // driver.findElement(By.xpath(ReserveNameElement.INTRO_SELECT_COMPANY_TYPE)).sendKeys("Incorp"); Select dropdown = new Select(driver.findElement(By.xpath(ReserveNameElement.INTRO_SELECT_COMPANY_TYPE))); dropdown.selectByVisibleText("Incorporated"); driver.findElement(By.xpath(ReserveNameElement.INTRO_BUTTON_NEXT)).click(); // WebDriver driver = new FirefoxDriver(); // LoginTester login = new LoginTester(driver); // IncorporatedTester tester = new IncorporatedTester(driver); // // login.start(); // //Maximize the browser // driver.manage().window().maximize(); // tester.start(); // tester.stop(); // // Click on Math Calculators // driver.findElement(By.xpath(".//*[@id='hcalc']/table/tbody/tr/td[2]/div[3]/a")).click(); // // // Click on Percent Calculators // driver.findElement(By.xpath(".//*[@id='content']/ul[1]/li[3]/a")).click(); // // // Enter value 10 in the first number of the percent Calculator // driver.findElement(By.id("cpar1")).sendKeys(data.getNumberText(2)); // // // Enter value 50 in the second number of the percent Calculator // driver.findElement(By.id("cpar2")).sendKeys(data.getNumberText(2)); // // // Click Calculate Button // driver.findElement(By.xpath(".//*[@id='content']/table[1]/tbody/tr[2]/td/input[2]")).click(); // // // // Get the Result Text based on its xpath // String result = driver.findElement(By.xpath(".//*[@id='content']/p[2]/font/b")).getText(); // // // // Print a Log In message to the screen // System.out.println(" The Result is " + result); //Close the Browser. driver.close(); }
From source file:cc.kune.selenium.PageObject.java
License:GNU Affero Public License
/** * Checks if is element present./*from www . j a va 2 s . c o m*/ * * @param id * the id * @return true, if is element present */ public boolean isElementPresent(final String id) { final Wait<WebDriver> wait = new WebDriverWait(webdriver, 5); final WebElement element = wait.until(visibilityOfElementLocated(By.id(id))); return element != null; }
From source file:ch.vorburger.vaadin.designer.tests.web.DesignerWebDriverTest.java
License:Apache License
@BeforeClass public static void setUpClass() throws Exception { // This is needed (only) for stand-alone EMF initialization SamplescreenPackage.eINSTANCE.eClass(); final String path = "/ch/vorburger/vaadin/designer/samplescreen/screen1.xmi"; URL url = DesignerWebDriverTest.class.getResource(path); if (url == null) throw new IOException("Could not getResource() for " + path); screen = new EIO().load(URI.createURI(url.toString()), Screen.class); driver = newWebDriver();//from www. ja va 2s . co m wait = new WebDriverWait(driver, 10); action = new Actions(driver); server = new DesignerServer(); server.start(); root = new SampleFixedScreenComponent(); new SampleFixedScreenBinding().bind(root, screen); server.getDesignerApplication().setRootContent(root); driver.get(server.getURL()); wait.until(ExpectedConditions.elementToBeClickable(By.id("name"))); }
From source file:ch.vorburger.webdriver.reporting.tests.SampleGoogleSearchReportTest.java
License:Apache License
@Test public void testGoogleSearch() { EventFiringWebDriver driverWithReporting; {//from w w w .ja v a 2 s . c o m // System.setProperty("webdriver.chrome.driver", "/opt/google/chrome/chrome"); // WebDriver driver = new ChromeDriver(); WebDriver driver = new FirefoxDriver(); WebDriverEventListener loggingListener = new LoggingWebDriverEventListener(LOG_FILE_WRITER); ; driverWithReporting = new EventFiringWebDriver(driver); driverWithReporting.register(loggingListener); } driverWithReporting.get("http://www.google.com"); WebElement element = driverWithReporting.findElement(By.name("q")); element.sendKeys("Mifos"); element.submit(); (new WebDriverWait(driverWithReporting, 10)) .until(ExpectedConditions.presenceOfElementLocated(By.id("bfoot"))); driverWithReporting.quit(); }
From source file:chromedriveryahoologin.ChromeDriverDeleteTrashEmails.java
public static void main(String[] args) { try {//from w ww .ja va 2 s . co m Integer pozSpam = 0; Integer pozTrash = 0; Integer pozHelp = 0; Integer pozCompose = 0; Integer pozNewFolder = 0; System.setProperty("webdriver.chrome.driver", "D:\\Proiecte\\selenium-java-2.47.1\\selenium-2.47.1\\chromedriver_win32\\chromedriver.exe"); System.setProperty("webdriver.chrome.logfile", "D:\\prjAutJava\\YahooLogin\\ChromeDriverDeleteSpam.log"); ChromeOptions options = new ChromeOptions(); options.addArguments("test-type"); options.addArguments("--start-maximized"); options.addArguments("--disable-web-security"); options.addArguments("--no-proxy-server"); options.addArguments("--disable-extensions"); options.addArguments("--disable-notifications"); options.addArguments("--disable-popup-blocking"); options.addArguments("--disable-plug-in"); Map<String, Object> prefs = new HashMap<String, Object>(); prefs.put("credentials_enable_service", false); prefs.put("profile.password_manager_enabled", false); options.setExperimentalOption("prefs", prefs); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability(ChromeOptions.CAPABILITY, options); capabilities.setCapability(CapabilityType.SUPPORTS_APPLICATION_CACHE, true); capabilities.setCapability(CapabilityType.SUPPORTS_FINDING_BY_CSS, true); capabilities.setCapability(CapabilityType.SUPPORTS_LOCATION_CONTEXT, true); capabilities.setCapability(CapabilityType.SUPPORTS_ALERTS, true); capabilities.setCapability(CapabilityType.PLATFORM, "WIN10"); driver = new ChromeDriver(capabilities); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); driver.get("https://mail.yahoo.com"); driver.manage().window().maximize(); WebElement usernameElem = driver.findElement(By.id("login-username")); usernameElem.sendKeys("andadeacu@yahoo.com"); WebElement Next = driver.findElement(By.name("signin")); Next.click(); driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); WebElement passwordElem = driver.findElement(By.xpath("//input[@id='login-passwd']")); boolean selected = passwordElem.isSelected(); CharSequence password = ""; passwordElem.sendKeys(password); WebElement login = driver.findElement(By.id("login-signin")); login.click(); driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); driver.switchTo().activeElement(); WebElement tooltipElem = driver.findElement(By.xpath("//div[@class='Pos(r) M(0) TooltipContent']")); List<WebElement> childs = tooltipElem.findElements(By.xpath("//ul/li")); for (int j = 0; j < childs.size(); j++) { WebElement spamElem = childs.get(j); /* * System.out.println("ancorele " + j + " " + " tag " + * childs.get(j).getTagName() + " " + childs.get(j).getText() + * " " + childs.get(j).getAttribute("innerHTML")); */ if (spamElem.getText().startsWith(("Spam"))) { pozSpam = j; } if (spamElem.getText().startsWith(("Help"))) { pozHelp = j; } if (spamElem.getText().startsWith(("Compose"))) { pozCompose = j; } if (spamElem.getText().startsWith(("New"))) { pozNewFolder = j; } if (spamElem.getText().startsWith(("Trash"))) { System.out.println(j + " Trash is " + spamElem.getTagName() + " " + spamElem.getText()); pozTrash = j; break; } } System.out.println(pozTrash); WebElement trashElem = childs.get(pozTrash); /* * System.out.println("trashElem " + trashElem.getTagName() + * " text " + trashElem.getText() + " class_atribute " + * trashElem.getAttribute("class") + " data_action " + * trashElem.getAttribute("data_action")); */ WebElement trashFolderEmpty = trashElem.findElement( By.xpath("//a[@class='x-gap btn btn-trash']/span/span[@class='btn icon icon-delete']")); /* * System.out.println("spamEmptyFolder " + * spamFolderEmpty.getTagName() + " text " + * spamFolderEmpty.getText() + " location " + * spamFolderEmpty.isEnabled()); */ trashFolderEmpty.click(); int timeOut = 5; WebDriverWait wait = new WebDriverWait(driver, timeOut); driver.switchTo().alert(); /* for Chrome is not working WebElement modalPopUp = driver.findElement(By .className("modal-hd yui3-widget-hd")); */ WebElement btnDeleteSpamEmails = driver.findElement(By.className("btn left right default")); /* * <button id="okayModalOverlay" class="btn left right default" * title="OK" role="button" data-action="ok">OK</button> */ btnDeleteSpamEmails.click(); driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); driver.switchTo().activeElement(); // verify msg after you delete spam emails System.out.println(driver.getCurrentUrl()); driver.quit(); } catch (Exception ex) { ex.printStackTrace(); driver.quit(); } }
From source file:cls.ui.model.selenium.carDealerManage.BasicInfoPage.java
public Boolean isLoadSuccess() { driver.switchTo().defaultContent();// w w w. j av a 2 s .c o m driver.switchTo().frame("iframe_undefined"); new WebDriverWait(driver, 5).until(ExpectedConditions.presenceOfElementLocated(By.id("dealerName"))); Boolean flag = false; WebElement dealerName = driver.findElement(By.id("dealerName")); if (dealerName != null) { flag = true; } return flag; }
From source file:co.edu.icesi.i2t.slrtools.bib.transformations.TransformBibACM.java
License:Open Source License
/** * Funcion principal para la transformacion de los archivos html en un solo * arhivo consolidado BIB, la funcion se encarga de extraer del html cada * link de articulo, despues de tener el listado de url se dispone con la * ayuda de selenium webdriver el ingreso a cada url y descargar el BIBtex * para finalizar con la union de todos en un solo archivo BIB * * @param sourceFilesPath String con la ruta de la carpeta donde se * encuentran los archivos html a transformas * @param targetFilePath String con la ruta fisica del directorio donde se * guardara el archivo consolodidao// w w w . j a va 2 s . c om * @param targetFileName */ public static boolean transformFiles(String sourceFilesPath, String targetFilePath, String targetFileName) { boolean bibFileCreated = false; System.out.println(""); System.out.println("-----------------------------"); System.out.println("Generating BibTeX for ACM Digital Library results..."); System.out.println(""); String bibContent = ""; List<String> urls = extractURL(sourceFilesPath); FirefoxProfile profile = new FirefoxProfile(); WebDriver webDriver = new FirefoxDriver(profile); for (int i = 0; i < urls.size(); i++) { try { System.out.println("[INFO] Retrieving BibTeX from URL: " + urls.get(i)); String idFile = urls.get(i).split("id=")[1].split("&")[0]; idFile = idFile.substring(idFile.indexOf(".") + 1, idFile.length()); String url = (urls.get(i)); webDriver.get(url); WebElement bibField = (new WebDriverWait(webDriver, 10)) .until(ExpectedConditions.presenceOfElementLocated(By.linkText("BibTeX"))); try { Thread.sleep(2000); } catch (InterruptedException e) { } bibField.click(); WebElement textBib = (new WebDriverWait(webDriver, 10)) .until(ExpectedConditions.presenceOfElementLocated(By.id(idFile))); String reference = textBib.getText(); String referenceAbstract = webDriver.findElement(By.id("abstract")).getText(); referenceAbstract = "abstract = {" + referenceAbstract + "}}" + System.lineSeparator(); bibContent += reference.substring(0, reference.length() - 2) + referenceAbstract; //Thread.sleep(10000); //tempurl.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); } catch (TimeoutException e) { System.out.println( "[ERROR] Failed to retrieve BibTex. The application may have been blocked by ACM Digital Library. Try again later."); } catch (Exception e) { System.out.println("[ERROR] Failed to retrieve BibTeX. " + e.getMessage()); } } webDriver.quit(); try { saveBibFile(bibContent, targetFilePath, targetFileName); if (!bibContent.equals("")) { bibFileCreated = true; } } catch (Exception e) { System.out.println("[ERROR] Failed to create BibTeX file." + e.getMessage()); } System.out.println("-----------------------------"); return bibFileCreated; }