List of usage examples for org.openqa.selenium WebDriver findElements
@Override List<WebElement> findElements(By by);
From source file:org.mitre.mpf.wfm.ui.NodesAndProcessPage.java
License:Open Source License
public List<String> getCurrentNodesAndProcessFromNodeManager(WebDriver driver, String node_mgr_url) { log.info("Checking node manager at {}", node_mgr_url); // load the node manager page driver.get(node_mgr_url);// ww w. j a v a2s. com // Wait for the login page to load, timeout after 10 seconds (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return NodesAndProcessPage.ValidNodeManagerPage(d); } }); log.info("Looking for element meta"); WebElement meta = driver.findElement(By.xpath("//meta")); // meta List<WebElement> rows = driver.findElements(By.xpath("//body/table[1]/tbody/tr"));// first table ArrayList<String> list = new ArrayList<String>(); log.info("Table found with [" + rows.size() + "] rows. Building list. "); for (int rnum = 1; rnum < rows.size(); rnum++) {// skip first (0) since // its the headers List<WebElement> columns = rows.get(rnum).findElements(By.tagName("td")); list.add(columns.get(0).getText() + ":" + columns.get(1).getText() + ":" + columns.get(2).getText());// name:rank:state } return list; }
From source file:org.mitre.mpf.wfm.ui.UploadMediaPage.java
License:Open Source License
/*** * // w ww.jav a 2 s.co m * @param driver * @param base_url * @return */ public String uploadMediaFromUrl(WebDriver driver, String base_url, String media_url) throws InterruptedException { if (!UploadMediaPage.ValidPage(driver)) { throw new IllegalStateException( "This is not the correct page, current page" + "is: " + driver.getCurrentUrl()); } //click on the remote-media directory and wait for it List<WebElement> rows = driver.findElements(By.className("list-group-item")); int idx = rows.size(); //log.info("#level directories:" + idx); boolean found = false; for (WebElement row : rows) { String ele = row.getText(); //log.info(ele); if (ele.equals("remote-media")) { row.click(); found = true; } } if (!found) { // Using the TestNG API for logging throw new IllegalStateException("remote-media not found " + driver.getCurrentUrl()); } log.info("Clicking btn-upload and wating for modal"); Utils.safeClickByClassname(driver, "btn-upload"); // wait for modal to popup (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.findElement(By.id("submitURLs")) != null; } }); log.info("sending media :" + media_url); driver.findElement(By.id("URLsInput")).sendKeys(media_url);//insert a img url log.info("clicking submit"); Utils.safeClickById(driver, "submitURLs"); log.info("Waiting for file upload 600s {}", media_url); (new WebDriverWait(driver, 600)).until(new ExpectedCondition<Boolean>() { public Boolean apply(WebDriver d) { return d.findElement(By.className("localName")).getText().contains("Uploaded: "); } }); log.info("File uploaded"); log.info("clicking close"); Utils.safeClickById(driver, "cancelURLUpload"); Thread.sleep(600); return media_url; }
From source file:org.mitre.mpf.wfm.ui.Utils.java
License:Open Source License
public static List<WebElement> getClassValues(WebDriver driver, String classname) { List<WebElement> elements; try {//from w w w . ja v a2 s. c o m elements = driver.findElements(By.className(classname)); } catch (NoSuchElementException nse) { return null; } return elements; }
From source file:org.mousephenotype.www.testing.model.GraphValidatorPreqc.java
License:Apache License
public PageStatus validate(WebDriver driver, GenePage genePage, GraphTestDTO geneGraph) { PageStatus status = new PageStatus(); String message;/*from w ww .j av a2 s .co m*/ List<String> urls = genePage.getGraphUrls(geneGraph.getProcedureName(), geneGraph.getParameterName()); for (String url : urls) { if (!TestUtils.isPreQcLink(url)) { logger.info("Not a preqc graph. Continuing...: Gene Page URL: " + genePage.getTarget() + ". Graph URL: " + url); continue; } // If the graph page doesn't load, log it. driver.get(url); // Make sure there is a div.viz-tools. List<WebElement> elements = driver .findElements(By.xpath("//div[@class='viz-tools' or @class='phenodcc-heatmap']")); if (elements.isEmpty()) { message = "ERROR: " + "\n\tpreQc graph[ " + geneGraph.getProcedureParameterName() + "] URL: " + url + ". Gene page: " + genePage.getTarget() + "\n[FAILED]"; status.addError(message); } } return status; }
From source file:org.mozilla.zest.core.v1.ZestExpressionClientElementExists.java
License:Mozilla Public License
@Override public boolean isTrue(ZestRuntime runtime) { WebDriver wd = runtime.getWebDriver(this.getWindowHandle()); if (wd == null) { return false; }/*w w w . java2 s .co m*/ String elem = runtime.replaceVariablesInString(this.getElement(), false); By by = null; if ("className".equalsIgnoreCase(type)) { by = By.className(elem); } else if ("cssSelector".equalsIgnoreCase(type)) { by = By.cssSelector(elem); } else if ("id".equalsIgnoreCase(type)) { by = By.id(elem); } else if ("linkText".equalsIgnoreCase(type)) { by = By.linkText(elem); } else if ("name".equalsIgnoreCase(type)) { by = By.name(elem); } else if ("partialLinkText".equalsIgnoreCase(type)) { by = By.partialLinkText(elem); } else if ("tagName".equalsIgnoreCase(type)) { by = By.tagName(elem); } else if ("xpath".equalsIgnoreCase(type)) { by = By.xpath(elem); } else { return false; } return wd.findElements(by).size() > 0; }
From source file:org.mozilla.zest.core.v1.ZestLoopTokenClientElementsSet.java
License:Mozilla Public License
/** * private method for initialization of the loop (TokenSet & first state). * * @return the zest loop token string set * @throws ZestClientFailException //www . ja va 2s. c om */ protected ZestLoopTokenStringSet getConvertedSet() throws ZestClientFailException { if (this.convertedSet == null) { if (loop == null) { // Not yet initialized return null; } ZestLoopTokenStringSet set = new ZestLoopTokenStringSet(); WebDriver wd = this.loop.getRuntime().getWebDriver(getWindowHandle()); List<WebElement> weList; if ("className".equalsIgnoreCase(type)) { weList = wd.findElements(By.className(this.getElement())); } else if ("cssSelector".equalsIgnoreCase(type)) { weList = wd.findElements(By.cssSelector(this.getElement())); } else if ("id".equalsIgnoreCase(type)) { weList = wd.findElements(By.id(this.getElement())); } else if ("linkText".equalsIgnoreCase(type)) { weList = wd.findElements(By.linkText(this.getElement())); } else if ("name".equalsIgnoreCase(type)) { weList = wd.findElements(By.name(this.getElement())); } else if ("partialLinkText".equalsIgnoreCase(type)) { weList = wd.findElements(By.partialLinkText(this.getElement())); } else if ("tagName".equalsIgnoreCase(type)) { weList = wd.findElements(By.tagName(this.getElement())); } else if ("xpath".equalsIgnoreCase(type)) { weList = wd.findElements(By.xpath(this.getElement())); } else { throw new ZestClientFailException(this, "Unsupported type: " + type); } for (WebElement we : weList) { String val; if (this.attribute == null || this.attribute.length() == 0) { val = we.getText(); } else { val = we.getAttribute(attribute); } if (val != null && val.length() > 0) { set.addToken(val); } } this.convertedSet = set; } return convertedSet; }
From source file:org.netbeans.modules.jackpot30.web.ui.test.OverallTest.java
License:Open Source License
@Test public void overallTest() throws Exception { // WebDriver driver = new FirefoxDriver(); WebDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_10); ((HtmlUnitDriver) driver).setJavascriptEnabled(true); try {// w w w . j a v a 2 s. co m driver.get("http://localhost:" + System.getProperty("PORT", "9998") + "/index/ui/index.html"); //wait for the page to be rendered: new WebDriverWait(driver, 20).until(new Predicate<WebDriver>() { public boolean apply(WebDriver t) { List<WebElement> cb = t.findElements(By.id("projectCheckBox-data")); return !cb.isEmpty() && cb.get(0).isDisplayed(); } }); WebElement searchInput = driver.findElements(By.id("search-input")).get(0); searchInput.sendKeys("ClassA"); searchInput.submit(); WebElement link = new WebDriverWait(driver, 20).until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver t) { List<WebElement> cb = t.findElements(By.tagName("a")); for (WebElement we : cb) { String href = we.getAttribute("href"); if (href != null && href.contains("goto=CLASS:org.netbeans.modules.jackpot30.example.ClassA")) return we; } return null; } }); link.click(); WebElement methodIdentifierSpan = new WebDriverWait(driver, 20) .until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver t) { List<WebElement> cb = t.findElements(By.tagName("span")); for (WebElement we : cb) { String href = we.getAttribute("jpt30pos"); if (href != null && href.equals("88")) return we; } return null; } }); String classes = methodIdentifierSpan.getAttribute("class"); Assert.assertTrue(classes.contains("identifier") && classes.contains("method") && classes.contains("declaration") && classes.contains("public")); methodIdentifierSpan.click(); Assert.assertEquals( Arrays.asList("example/src/org/netbeans/modules/jackpot30/example/SubClassA.java", "example/src/org/netbeans/modules/jackpot30/example/UseClassA.java"), usagesList(driver)); findCheckbox(driver, "showUsages").click(); //uncheck Assert.assertEquals(Arrays.asList("example/src/org/netbeans/modules/jackpot30/example/SubClassA.java"), usagesList(driver)); findCheckbox(driver, "showUsages").click(); //check Assert.assertEquals( Arrays.asList("example/src/org/netbeans/modules/jackpot30/example/SubClassA.java", "example/src/org/netbeans/modules/jackpot30/example/UseClassA.java"), usagesList(driver)); findCheckbox(driver, "showSubtypes").click(); //uncheck Assert.assertEquals(Arrays.asList("example/src/org/netbeans/modules/jackpot30/example/UseClassA.java"), usagesList(driver)); findCheckbox(driver, "showSubtypes").click(); //uncheck Assert.assertEquals( Arrays.asList("example/src/org/netbeans/modules/jackpot30/example/SubClassA.java", "example/src/org/netbeans/modules/jackpot30/example/UseClassA.java"), usagesList(driver)); } finally { driver.quit(); } }
From source file:org.netbeans.modules.jackpot30.web.ui.test.OverallTest.java
License:Open Source License
private List<String> usagesList(WebDriver driver) { Iterable<WebElement> usages = new WebDriverWait(driver, 20) .until(new Function<WebDriver, Iterable<WebElement>>() { public Iterable<WebElement> apply(WebDriver t) { List<WebElement> cb = t.findElements(By.className("usages")); if (cb.isEmpty()) return null; return cb; }/*from www . ja va 2 s . c o m*/ }); List<String> usageStrings = new ArrayList<String>(); for (WebElement we : usages) { if (!we.isDisplayed()) continue; usageStrings.add(we.getText()); } return usageStrings; }
From source file:org.netbeans.modules.jackpot30.web.ui.test.OverallTest.java
License:Open Source License
private WebElement findCheckbox(WebDriver driver, final String id) { return new WebDriverWait(driver, 20).until(new Function<WebDriver, WebElement>() { public WebElement apply(WebDriver t) { List<WebElement> cb = t.findElements(By.id(id)); if (cb.isEmpty()) return null; return cb.get(0); }//www. j ava 2 s . c om }); }
From source file:org.nuxeo.ftest.cap.ITRichfileUploadTest.java
License:Apache License
@Test public void testRichFileUpload() throws IOException, UserNotConnectedException { login();//from w w w .ja v a 2s .co m open(TEST_FILE_URL); // Go to Files tab asPage(DocumentBasePage.class).clickOnDocumentTabLink(driver.findElement(By.xpath(FILES_TAB_XPATH))); // check that clear all is not visible assertFalse(Locator.findElement(By.xpath(RF_CLEAN_ALL_ID_XPATH)).isDisplayed()); // select a file final String mockFile1 = getTmpFileToUploadPath("dummy", "test", "txt"); Locator.findElement(By.xpath(RF_FILE_UPLOAD_INPUT_XPATH)).sendKeys(mockFile1); // check that submit button appears Locator.waitUntilElementPresent(By.xpath(STORE_UPLOAD_FILE_INPUT_VALUE_XPATH)); // check that clear all is visible assertTrue(Locator.findElement(By.xpath(RF_CLEAN_ALL_ID_XPATH)).isDisplayed()); // check that there is one item with the clear link List<WebElement> clearLinks = driver.findElements(By.xpath(RF_UPLOADED_FILE_ITEMS_XPATH)); assertEquals(1, clearLinks.size()); // we click the clear link clearLinks.get(0).click(); // check the submit button disappears Locator.waitUntilElementNotPresent(By.xpath(STORE_UPLOAD_FILE_INPUT_VALUE_XPATH)); // check there is not item clearLinks = driver.findElements(By.xpath(RF_UPLOADED_FILE_ITEMS_XPATH)); assertEquals(0, clearLinks.size()); // check that clear all is not visible assertFalse(driver.findElement(By.xpath(RF_CLEAN_ALL_ID_XPATH)).isDisplayed()); // do it again but with two files and use clear all final String mockFile2 = getTmpFileToUploadPath("dummy", "test", "txt"); final String mockFile3 = getTmpFileToUploadPath("dummy", "test", "txt"); Locator.findElement(By.xpath(RF_FILE_UPLOAD_INPUT_XPATH)).sendKeys(mockFile2); Locator.waitUntilElementPresent(By.xpath(STORE_UPLOAD_FILE_INPUT_VALUE_XPATH)); Locator.findElementWithTimeout(By.xpath(RF_FILE_UPLOAD_INPUT_XPATH)).sendKeys(mockFile3); // check we have 2 items clearLinks = driver.findElements(By.xpath(RF_UPLOADED_FILE_ITEMS_XPATH)); assertEquals(2, clearLinks.size()); // clear all driver.findElement(By.xpath(RF_CLEAN_ALL_ID_XPATH)).click(); // check submit disappears Locator.waitUntilElementNotPresent(By.xpath(STORE_UPLOAD_FILE_INPUT_VALUE_XPATH)); // check we have 0 items Locator.waitUntilGivenFunction(new Function<WebDriver, Boolean>() { @Override public Boolean apply(WebDriver driver) { return driver.findElements(By.xpath(RF_UPLOADED_FILE_ITEMS_XPATH)).size() == 0; } }); // check that clear all is not visible assertFalse(driver.findElement(By.xpath(RF_CLEAN_ALL_ID_XPATH)).isDisplayed()); // upload 2 and submit final String mockFile4 = getTmpFileToUploadPath("dummy", "test", "txt"); final String mockFile5 = getTmpFileToUploadPath("dummy", "test", "txt"); Locator.findElementWithTimeout(By.xpath(RF_FILE_UPLOAD_INPUT_XPATH)).sendKeys(mockFile4); Locator.waitUntilElementPresent(By.xpath(STORE_UPLOAD_FILE_INPUT_VALUE_XPATH)); Locator.findElementWithTimeout(By.xpath(RF_FILE_UPLOAD_INPUT_XPATH)).sendKeys(mockFile5); Function<WebDriver, Boolean> function = new Function<WebDriver, Boolean>() { @Override public Boolean apply(WebDriver driver) { try { driver.findElement(By.xpath(STORE_UPLOAD_FILE_INPUT_VALUE_XPATH)).click(); return false; } catch (NoSuchElementException e) { return true; } } }; Locator.waitUntilGivenFunctionIgnoring(function, StaleElementReferenceException.class); // check we have 2 uploaded files List<WebElement> uploadedFiles = driver.findElements(By.xpath(NX_UPLOADED_FILES_XPATH)); assertEquals(2, uploadedFiles.size()); // remove the first one removeFirstUploadedItem(); // check we have 1 uploaded file Locator.waitUntilGivenFunction(new Function<WebDriver, Boolean>() { @Override public Boolean apply(WebDriver driver) { return driver.findElements(By.xpath(NX_UPLOADED_FILES_XPATH)).size() == 1; } }); // reselect file and check Clear All and individual clear are still // rerendered correctly final String mockFile6 = getTmpFileToUploadPath("dummy", "test", "txt"); Locator.findElement(By.xpath(RF_FILE_UPLOAD_INPUT_XPATH)).sendKeys(mockFile6); // check that submit button appears Locator.waitUntilElementPresent(By.xpath(STORE_UPLOAD_FILE_INPUT_VALUE_XPATH)); // check that clear all is visible assertTrue(driver.findElement(By.xpath(RF_CLEAN_ALL_ID_XPATH)).isDisplayed()); // check that there is one item with the clear link clearLinks = driver.findElements(By.xpath(RF_UPLOADED_FILE_ITEMS_XPATH)); assertEquals(1, clearLinks.size()); // clear all Locator.findElementWithTimeoutAndClick(By.xpath(RF_CLEAN_ALL_ID_XPATH)); // check submit disappears Locator.waitUntilElementNotPresent(By.xpath(RF_UPLOADED_FILE_ITEMS_XPATH)); // check we have 0 items clearLinks = driver.findElements(By.xpath(RF_UPLOADED_FILE_ITEMS_XPATH)); assertEquals(0, clearLinks.size()); // remove remaining item removeFirstUploadedItem(); // wait for message to be present for ajax request to be finished before logout Locator.waitForTextPresent(By.id("ambiance-notification"), "File modified"); // logout removed to avoid random exception on server (probably an unfinished ajax request) }