List of usage examples for org.openqa.selenium WebDriver getTitle
String getTitle();
From source file:org.qe4j.web.OpenWebDriverTest.java
License:Open Source License
@Test public void getTitle() throws IOException { Properties properties = getProperties(); WebDriver driver = new OpenWebDriver(properties); driver.get(URL);//from w w w . j a v a 2 s. c om Assert.assertEquals(driver.getTitle(), URL_TITLE, "title"); }
From source file:org.qe4j.web.OpenWebDriverTest.java
License:Open Source License
@Test public void multipleInstances() throws IOException { Properties properties = getProperties(); WebDriver driver1 = new OpenWebDriver(properties); WebDriver driver2 = new OpenWebDriver(properties); Assert.assertNotSame(driver1, driver2, "drivers not the same"); Assert.assertNotNull(driver1, "driver1 exists"); Assert.assertNotNull(driver2, "driver2 exists"); Assert.assertNotSame(driver1, driver2, "different drivers made"); driver1.get(URL);//from w ww .ja v a 2s . c o m driver2.get(URL2); Assert.assertEquals(driver1.getTitle(), URL_TITLE, "driver1 title"); driver1.quit(); Assert.assertEquals(driver2.getTitle(), URL2_TITLE, "driver2 title"); }
From source file:org.rivalry.core.datacollector.DefaultDataCollector.java
License:Open Source License
/** * @param webDriver Web driver.//from w w w . java 2 s . c o m * @param dcSpec Data collector specification. * @param rivalryData Rivalry data. * @param candidate Candidate. */ void fetchData(final WebDriver webDriver, final DCSpec dcSpec, final RivalryData rivalryData, final Candidate candidate) { final long start = System.currentTimeMillis(); // And now use this to visit a web page. final String url = candidate.getPage(); if (StringUtils.isNotEmpty(url)) { System.out.println("Accessing URL " + url); webDriver.get(url); } for (final DCSelector selector : dcSpec.getSelectors()) { final SelectorType type = selector.getType(); switch (type) { case CLICK: final DCSelector childSelector = selector.getSelectors().get(0); final SelectorType childType = childSelector.getType(); final String childValue = childSelector.getValue(); LOGGER.debug("childType = " + childType + " childValue = " + childValue); childType.findElement(webDriver, childValue).click(); LOGGER.debug("2 Page title is: " + webDriver.getTitle()); break; case SUBMIT: type.findElement(webDriver, selector.getValue()).submit(); break; default: final List<WebElement> parents = type.findElements(webDriver, selector.getValue()); for (final WebElement parent : parents) { process(rivalryData, candidate, parent, selector.getSelectors()); } } } final long end = System.currentTimeMillis(); logTiming(candidate.getName() + " 2 fetchData()", start, end); }
From source file:org.rstudio.studio.selenium.BootRStudio.java
License:Open Source License
@Test public void testRStudioBoot() throws Exception { WebDriver driver = RStudioWebAppDriver.start(); // Check the title of the page assertEquals(driver.getTitle(), "RStudio"); // Close the browser RStudioWebAppDriver.stop();/*from ww w. ja v a 2 s . co m*/ }
From source file:org.safs.selenium.webdriver.lib.SearchObject.java
License:Open Source License
/** * @param title String, the case-insensitive title within the WebDriver stored in the Hashtable.<br> * if user provides null or a zero-length title then the last used WebDriver will be returned.<br> * the routine does not (yet) set the found WebDriver to be the lastUsedWD. That might change, though. * @return WebDriver, the WebDriver associated with the browser title; null if no matching WebDriver is found. *//* w w w . j a v a2 s .com*/ protected synchronized static WebDriver getWebDriverWithTitle(String title) { String debugmsg = StringUtils.debugmsg(SearchObject.class, "getWebDriverWithTitle"); WebDriver temp = null; WebDriver match = null; String lctitle = null; if (title != null && title.length() > 0) { lctitle = title.toLowerCase().trim(); Enumeration e = webDrivers.elements(); while (e.hasMoreElements()) { temp = (WebDriver) e.nextElement(); try { if (lctitle.equals(temp.getTitle().toLowerCase().trim())) { match = temp; break; } } catch (NullPointerException notitle) { } } } else match = lastUsedWD; if (match == null) IndependantLog.warn(debugmsg + "cannot get WebDriver with title '" + title + "'"); return match; }
From source file:org.safs.selenium.webdriver.lib.SearchObject.java
License:Open Source License
/** * @return String[] of all known WebDriver window titles, or an empty array. *//* www . ja v a 2s . c o m*/ public synchronized static String[] getAllWindowTitles() { String debugmsg = StringUtils.debugmsg(SearchObject.class, "getAllWindowTitles"); WebDriver temp = null; if (webDrivers.isEmpty()) { getWebDriver(); if (webDrivers.isEmpty()) return new String[0]; } ArrayList<String> titles = new ArrayList(); Enumeration list = webDrivers.elements(); String browser = null; for (int i = 0; i < webDrivers.size(); i++) { temp = (WebDriver) list.nextElement(); try { titles.add(temp.getTitle()); } catch (Exception ignore) { } } IndependantLog.info(debugmsg + "retrieved " + titles.size() + " window titles."); return titles.toArray(new String[0]); }
From source file:org.safs.selenium.webdriver.lib.WDLibrary.java
License:Open Source License
/** * Attempt to SetFocus on the topmost window for the provided WebDriver. * @param adriver WebDriver from which to get the window title * @return boolean true if the window is focused. * @throws SeleniumPlusException if an error occured during the execution attempt. * @see #windowSetFocus(String)//from w ww.jav a 2 s. c om */ public static boolean windowSetFocus(WebDriver adriver) throws SeleniumPlusException { boolean rc = false; IndependantLog.info("WDLibrary.windowSetFocus set focus via WebDriver window title"); try { rc = windowSetFocus(adriver.getTitle()); } catch (Exception x) { IndependantLog.info("WDLibrary.windowSetFocus RemoteWebElement ignoring " + getThrowableMessages(x) + ": " + x.getMessage()); } return rc; }
From source file:org.springframework.springfaces.integrationtest.selenium.page.PageObject.java
License:Apache License
/** * Create a new {@link PageObject} instance. * @param webDriver the web driver/*from w ww . j a v a 2 s . c o m*/ */ public PageObject(WebDriver webDriver) { Assert.notNull(webDriver, "WebDriver must not be null"); this.webDriver = webDriver; String title = webDriver.getTitle(); Assert.isTrue(isCorrectPage(title), "Incorrect page ('" + title + "') loaded"); }
From source file:org.structr.web.frontend.selenium.SeleniumTest.java
License:Open Source License
/** * Login into the backend UI as admin/admin using the given web driver and switch to the given menu entry. * * @param menuEntry//from w ww .j a v a 2s . c o m * @param driver * @param waitForSeconds */ protected static void loginAsAdmin(final String menuEntry, final WebDriver driver, final int waitForSeconds) { driver.get("http://localhost:8875/structr/#" + menuEntry.toLowerCase()); final WebDriverWait wait = new WebDriverWait(driver, waitForSeconds); //wait.until((ExpectedCondition<Boolean>) (final WebDriver f) -> (Boolean) ((JavascriptExecutor) f).executeScript("LSWrapper.isLoaded()")); assertEquals("Username field not found", 1, driver.findElements(By.id("usernameField")).size()); assertEquals("Password field not found", 1, driver.findElements(By.id("passwordField")).size()); assertEquals("Login button not found", 1, driver.findElements(By.id("loginButton")).size()); final WebElement usernameField = wait .until(ExpectedConditions.visibilityOfElementLocated(By.id("usernameField"))); final WebElement passwordField = wait .until(ExpectedConditions.visibilityOfElementLocated(By.id("passwordField"))); final WebElement loginButton = wait .until(ExpectedConditions.visibilityOfElementLocated(By.id("loginButton"))); usernameField.sendKeys("admin"); passwordField.sendKeys("admin"); loginButton.click(); try { wait.until(ExpectedConditions.titleIs("Structr " + menuEntry)); } catch (WebDriverException wex) { try { Runtime.getRuntime().exec( "/usr/bin/jstack -l $(ps xa|grep structr|grep java|tail -n1|awk '{print $1}') > /tmp/jstack.out." + new Date().getTime()); } catch (IOException ex1) { throw new RuntimeException(ex1); } } catch (RuntimeException ex) { throw ex; } assertEquals("Structr " + menuEntry, driver.getTitle()); }
From source file:org.suren.autotest.web.framework.selenium.WebPage.java
License:Apache License
@Override public void closeOthers() { String currentTitle = getTitle(); String currentWinHandle = engine.getDriver().getWindowHandle(); for (String winHandle : engine.getDriver().getWindowHandles()) { WebDriver itemDrive = engine.getDriver().switchTo().window(winHandle); if (!itemDrive.getTitle().equals(currentTitle)) { itemDrive.close();// w ww .java2 s . c om } } engine.getDriver().switchTo().window(currentWinHandle); }