List of usage examples for org.openqa.selenium WebDriver findElements
@Override List<WebElement> findElements(By by);
From source file:org.richfaces.tests.metamer.ftest.extension.attributes.collector.vdl.AttributesCollectorFromVDL.java
License:Open Source License
@Override public Map<String, List<String>> collectAttributes() { WebDriver browser = new FirefoxDriver(); try {// www . j av a 2s . c om browser.get(VDL_DOC_URL_ALLTAGS_NOFRAMES); List<WebElement> linksElements = browser.findElements(By.cssSelector("li a")); Map<String, List<String>> result = Maps.newHashMap(); List<String> attributes; List<WebElement> tables; WebElement correctAttributesTable; for (String link : getLinksURLFromElements(linksElements)) { browser.get(link); attributes = Lists.newArrayList(); tables = browser.findElements(By.cssSelector(TABLE_OVERVIEW_SUMMARY)); correctAttributesTable = null; for (WebElement table : tables) { if (table.findElement(By.cssSelector(CAPTION_SPAN)).getText().toLowerCase() .contains(ATTRIBUTES)) { correctAttributesTable = table; break; } } if (correctAttributesTable != null) { for (WebElement attributeElement : correctAttributesTable .findElements(By.cssSelector(TBODY_TR))) { attributes.add(attributeElement.getAttribute(ID)); } result.put(getComponentNameFromActualPage(browser), attributes); } } return result; } finally { browser.quit(); } }
From source file:org.rivalry.example.bookaward.MysteryAwardDataCollector.java
License:Open Source License
@Override public void fetchData(final DCSpec dcSpec, final String username, final String password, final RivalryData rivalryData) { final long start = System.currentTimeMillis(); final String author = username; final Criterion criterion = getCriterion(rivalryData, author); final WebDriver webDriver = createWebDriver(); webDriver.get(dcSpec.getUrl());/* w w w . j av a 2 s . c o m*/ final List<WebElement> webElements = webDriver.findElements(By.className("r")); for (final WebElement webElement : webElements) { final WebElement anchor = webElement.findElement(By.tagName("a")); final String name = parseName(anchor.getText()); final String page = anchor.getAttribute("href"); final Candidate candidate = getCandidate(rivalryData, name, page); candidate.putValue(criterion, 1); } final long end = System.currentTimeMillis(); logTiming("0 fetchData()", start, end); }
From source file:org.rivalry.example.dogbreed.DefaultDataCollectorTest.java
License:Open Source License
/** * Test the <code>fetchData()</code> method. *//* w w w . j a v a2 s .com*/ @Ignore @Test public void directTest() { System.out.println("start directTest()"); final WebDriver webDriver = createWebDriver(); webDriver.get("http://dogtime.com/dog-breeds/boston-terrier"); final List<WebElement> groups = webDriver.findElements(By.className("breed-characteristic-group")); final WebElement seeAllCharacteristics = groups.get(groups.size() - 1); System.out.println("seeAllCharacteristics = " + seeAllCharacteristics); System.out.println("seeAllCharacteristics.getText() = [" + seeAllCharacteristics.getText() + "]"); groups.get(groups.size() - 1).click(); final WebElement parent = webDriver.findElement(By.className("characteristics")); assertNotNull(parent); assertTrue(parent.isDisplayed()); assertTrue(parent.isEnabled()); final List<WebElement> ratings = parent.findElements(By.className("five-star-ratings")); assertNotNull(ratings); assertThat(ratings.size(), is(25)); { final WebElement element = ratings.get(0); System.out.println("element = " + element); assertNotNull(element); assertThat(element.getAttribute("class"), is("five-star-ratings five-star-ratings-5")); } { final WebElement element = ratings.get(1); assertNotNull(element); assertThat(element.getAttribute("class"), is("five-star-ratings five-star-ratings-4")); } final List<WebElement> h3s = parent.findElements(By.tagName("h3")); assertNotNull(h3s); assertThat(h3s.size(), is(25)); { final WebElement element = h3s.get(0); System.out.println("element.getText() = [" + element.getText() + "]"); assertNotNull(element); assertThat(element.getText(), is("Adapt well to apartment living")); } { final WebElement element = h3s.get(1); System.out.println("element.getText() = [" + element.getText() + "]"); assertNotNull(element); assertThat(element.getText(), is("Affectionate with family")); } System.out.println("end directTest()"); }
From source file:org.rstudio.studio.selenium.ConsoleTestUtils.java
License:Open Source License
public static void beginConsoleInteraction(final WebDriver driver) { // Wait for the console panel to load (new WebDriverWait(driver, 15)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { List<WebElement> elements = driver .findElements(By.id(ElementIds.getElementId(ElementIds.CONSOLE_INPUT))); return elements.size() > 0; }/*ww w. j a v a2 s.c o m*/ }); resumeConsoleInteraction(driver); }
From source file:org.rstudio.studio.selenium.DialogTestUtils.java
License:Open Source License
public static void waitForModalToDisappear(final WebDriver driver) { (new WebDriverWait(driver, 5)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { List<WebElement> elements = driver.findElements(By.className("gwt-DialogBox-ModalDialog")); return elements.size() == 0; }/*from w w w. j a v a2 s .c o m*/ }); }
From source file:org.rstudio.studio.selenium.MenuNavigator.java
License:Open Source License
public static WebElement getMenuItem(final WebDriver driver, String level1, String level2, String level3) { WebElement popupItem = getMenuItem(driver, level1, level2); Actions action = new Actions(driver); action.moveToElement(popupItem).build().perform(); // Wait for there to be two popups open (the level1 and level2 menus) (new WebDriverWait(driver, 1)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { List<WebElement> elements = driver.findElements(By.className("gwt-MenuBarPopup")); return elements.size() > 1; }/*from ww w .j a v a2 s. c o m*/ }); // Get the second popup menu List<WebElement> elements = driver.findElements(By.className("gwt-MenuBarPopup")); WebElement menu2popup = elements.get(1); return findMenuItemByName(menu2popup, level3); }
From source file:org.senchalabs.gwt.gwtdriver.gxt.models.ToolTip.java
License:Apache License
public static List<ToolTip> findAllActive(WebDriver driver) { List<WebElement> elts = driver .findElements(new ByChained(By.xpath("//body/*"), new ByWidget(driver, Tip.class))); List<ToolTip> tooltips = new ArrayList<ToolTip>(); for (WebElement elt : elts) { tooltips.add(new ToolTip(driver, elt)); }/*from w ww . j a v a2s .c om*/ return tooltips; }
From source file:org.sonarqube.report.extendedpdf.OverviewPDFReporter.java
License:Open Source License
private void captureScreenshot(WebDriver driver, String selector) throws IOException { File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); driver.get(dashboardUrl);/* w w w.ja v a 2 s . co m*/ System.out.println("Screenshot captured..."); List<WebElement> elements = driver.findElements(By.cssSelector(selector)); if (!elements.isEmpty()) { WebElement element = elements.get(0); BufferedImage fullImg = ImageIO.read(screenshot); Point point = element.getLocation(); int eleWidth = element.getSize().getWidth(); int eleHeight = element.getSize().getHeight(); BufferedImage eleScreenshot = fullImg.getSubimage(point.getX(), point.getY(), eleWidth, eleHeight); ImageIO.write(eleScreenshot, "png", screenshot); System.out.println("Cropping to get widget: " + selector.substring(1)); FileUtils.copyFile(screenshot, new File(screenshotsDir + File.separator + selector.substring(1) + ".png")); } }
From source file:org.specrunner.webdriver.impl.FinderXPath.java
License:Open Source License
@Override public List<WebElement> find(IContext context, IResultSet result, WebDriver client) throws PluginException { if (by == null) { throw new PluginException( "Element missing search strategy, use, for instance, the attribute by='id:txtName'."); }/*from www .j a v a 2s. co m*/ String type = getType(); String xpath = getXPath(context); List<WebElement> list = null; try { list = client.findElements(By.xpath(xpath)); } catch (Exception e) { throw new PluginException("Element " + type + " '" + xpath + "' not found.", e); } if (list == null) { throw new PluginException("Use \"by='<type>:<argument>'\" to select the element."); } return list; }
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 ww w .j a va2 s . 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()); }