List of usage examples for org.openqa.selenium WebDriver findElements
@Override List<WebElement> findElements(By by);
From source file:org.alfresco.po.share.FactorySharePage.java
License:Open Source License
/** * Helper method to return right Page for Share Dialogue displayed * * @return HtmlPage//from w w w . j a v a2s .c o m */ private HtmlPage resolveShareDialoguePage(WebDriver driver) { HtmlPage sharePage = null; try { List<WebElement> dialogues = driver.findElements(By.cssSelector(SHARE_DIALOGUE)); WebElement dialogue = null; for (WebElement e : dialogues) { if (e.isDisplayed()) { dialogue = e; break; } } WebElement copyMoveDialogue = null; try { copyMoveDialogue = driver.findElements(COPY_MOVE_DIALOGUE_SELECTOR).get(0); } catch (Exception e) { } if (dialogue != null && dialogue.isDisplayed()) { String dialogueID = dialogue.getAttribute("id"); if (dialogueID.contains("createSite")) { sharePage = instantiatePage(driver, CreateSitePage.class); } else if (dialogueID.contains("createFolder")) { sharePage = instantiatePage(driver, NewFolderPage.class); } else if (dialogueID.contains("upload")) { sharePage = instantiatePage(driver, UploadFilePage.class); } else if (dialogueID.contains("taggable-cntrl-picker")) { sharePage = instantiatePage(driver, TagPage.class); } else if (dialogueID.contains("editDetails") || dialogueID.contains("edit-metadata")) { sharePage = instantiatePage(driver, EditDocumentPropertiesPage.class); } else if (dialogueID.contains("copyMoveTo")) { sharePage = instantiatePage(driver, CopyOrMoveContentPage.class); } else if (dialogueID.contains("historicPropertiesViewer")) { sharePage = instantiatePage(driver, ViewPropertiesPage.class); } // The below dialogeId will be changed once this ACE-1047 issue is fixed. else if (dialogueID.contains("configDialog-configDialog_h")) { sharePage = instantiatePage(driver, ConfigureSiteNoticeDialogBoxPage.class); } else if (copyMoveDialogue != null && (copyMoveDialogue.getText().startsWith("Copy") || copyMoveDialogue.getText().startsWith("Move"))) { sharePage = instantiatePage(driver, CopyAndMoveContentFromSearchPage.class); } else if (dialogueID.contains("Create New Filter")) { sharePage = instantiatePage(driver, CreateNewFilterPopUpPage.class); } else if (dialogueID.contains("cloud-folder-title")) { sharePage = instantiatePage(driver, DestinationAndAssigneePage.class); } else if (dialogueID.contains("changeType")) { sharePage = instantiatePage(driver, ChangeTypePage.class); } else if (dialogueID.contains("default-aspects")) { sharePage = instantiatePage(driver, SelectAspectsPage.class); } String dialogueText = dialogue.getText(); if ("Create Site".equals(dialogueText)) { sharePage = instantiatePage(driver, CreateSitePage.class); } else if ("Edit Site Details".equals(dialogueText)) { sharePage = instantiatePage(driver, EditSitePage.class); } else if ("Create Model".equals(dialogueText)) { sharePage = instantiatePage(driver, CreateNewModelPopUp.class); } else if ("Create Custom Type".equals(dialogueText)) { sharePage = instantiatePage(driver, CreateNewCustomTypePopUp.class); } else if ("Create Aspect".equals(dialogueText)) { sharePage = instantiatePage(driver, CreateNewPropertyGroupPopUp.class); } else if ("Create Property".equals(dialogueText)) { sharePage = instantiatePage(driver, CreateNewPropertyPopUp.class); } else if ("Edit Model".equals(dialogueText)) { sharePage = instantiatePage(driver, EditModelPopUp.class); } else if ("Edit Custom Type".equals(dialogueText)) { sharePage = instantiatePage(driver, EditCustomTypePopUp.class); } else if ("Edit Aspect".equals(dialogueText)) { sharePage = instantiatePage(driver, EditPropertyGroupPopUp.class); } else if ("Edit Property".equals(dialogueText)) { sharePage = instantiatePage(driver, EditPropertyPopUp.class); } else if ("Apply the default layout".equals(dialogueText)) { sharePage = instantiatePage(driver, ApplyDefaultLayoutPopUp.class); } else if ("Delete Model".equals(dialogueText) || "Delete Custom Type".equals(dialogueText) || "Delete Aspect".equals(dialogueText) || "Delete Property".equals(dialogueText) || "Delete Site".equals(dialogueText)) { sharePage = instantiatePage(driver, ConfirmDeletePopUp.class); } else if ("Clear the Layout Designer".equals(dialogueText)) { sharePage = instantiatePage(driver, ClearFormLayoutPopUp.class); } else if ("Import Model".equals(dialogueText)) { sharePage = instantiatePage(driver, ImportModelPopUp.class); } else if ("Confirm Deletion".equals(dialogueText)) { sharePage = instantiatePage(driver, SearchConfirmDeletePage.class); } else if ("Copy Failed".equals(dialogueText) || "Move Failed".equals(dialogueText)) { sharePage = instantiatePage(driver, CopyOrMoveFailureNotificationPopUp.class); } else if ("Request Sent".equals(dialogueText)) { sharePage = instantiatePage(driver, ConfirmRequestToJoinPopUp.class); } } } catch (NoSuchElementException nse) { } return sharePage; }
From source file:org.alfresco.po.share.FootersPage.java
License:Open Source License
/** * @param driver/*w w w .j a va2 s . c o m*/ * @return */ private Map<String, String> getHeaderInfo(WebDriver driver) { String searchString = "Alfresco Enterprise v"; Map<String, String> headerMap = new HashMap<String, String>(); try { for (WebElement element : driver.findElements(HEADER_DETAILS)) { if (element.getText().contains(searchString)) { headerMap.put("productInfo", element.getText()); } } } catch (NoSuchElementException nse) { if (logger.isDebugEnabled()) { logger.error("FootersPage is not present"); } } return headerMap; }
From source file:org.alfresco.po.share.workflow.WorkFlowType.java
License:Open Source License
protected WebElement getTaskTypeElement(WebDriver driver) { By dropDown = By.cssSelector("div[id$='default-workflow-definition-menu'] li span.title"); List<WebElement> liElements = driver.findElements(dropDown); for (WebElement liElement : liElements) { String elementText = liElement.getText().trim(); if (elementText.equalsIgnoreCase(this.title.trim())) { return liElement; }/* w w w .j av a 2 s .co m*/ } return null; }
From source file:org.apache.nutch.protocol.interactiveselenium.DefaultClickAllAjaxLinksHandler.java
License:Apache License
public String processDriver(WebDriver driver) { String accumulatedData = ""; try {/*w ww.j a v a 2 s. c o m*/ driver.findElement(By.tagName("body")).getAttribute("innerHTML"); Configuration conf = NutchConfiguration.create(); new WebDriverWait(driver, conf.getLong("libselenium.page.load.delay", 3)); List<WebElement> atags = driver.findElements(By.tagName("a")); int numberofajaxlinks = atags.size(); for (int i = 0; i < numberofajaxlinks; i++) { if (atags.get(i).getAttribute("href") != null && atags.get(i).getAttribute("href").equals("javascript:void(null);")) { atags.get(i).click(); if (i == numberofajaxlinks - 1) { // append everything to the driver in the last round JavascriptExecutor jsx = (JavascriptExecutor) driver; jsx.executeScript( "document.body.innerHTML=document.body.innerHTML " + accumulatedData + ";"); continue; } accumulatedData += driver.findElement(By.tagName("body")).getAttribute("innerHTML"); // refreshing the handlers as the page was interacted with driver.navigate().refresh(); new WebDriverWait(driver, conf.getLong("libselenium.page.load.delay", 3)); atags = driver.findElements(By.tagName("a")); } } } catch (Exception e) { LOG.info(StringUtils.stringifyException(e)); } return accumulatedData; }
From source file:org.apache.nutch.protocol.interactiveselenium.ListImageHandler.java
License:Apache License
public void processDriver(WebDriver driver) { System.out.println("=========== Into Handler_vci_classifieds =========="); //Get the current page URL and store the value in variable 'url' String url = driver.getCurrentUrl(); //Print the value of variable in the console System.out.println("[ListImageHandler][processDriver] The current URL is: " + url); //Load a new page in the current browser windows driver.get(url);//from w w w.j a v a2 s. com // form-input structure for search bar // WebElement form = driver.findElement(By.tagName("form")); // List<WebElement> inputs = null; // if (form != null) { // inputs = form.findElements(By.tagName("input")); // for (WebElement elem : inputs) { // if (elem.isDisplayed()) { // elem.clear(); // elem.sendKeys("gun\n"); // System.out.println("[ListImageHandler][processDriver] Submit keyword \"gun\""); // //form.submit(); // break; // } // } // } // direct input html tag for search bar ArrayList<String> possibleName = new ArrayList<String>(); possibleName.add("q"); possibleName.add("searchtext"); possibleName.add("txtSearch"); WebElement element; if (inputs == null) { for (int i = 0; i < possibleName.size(); i++) { element = driver.findElement(By.name(possibleName.get(i))); if (element != null) { // send with "\n" == submit element.sendKeys("gun\n"); //element.sendKeys("gun"); //form.submit(); System.out.println("[ListImageHandler][processDriver] Submit keyword \"gun\""); break; } } } // wait for finsih loading webpage, hard code timer try { System.out.println("[ListImageHandler][processDriver] before sleep"); Thread.sleep(2000); System.out.println("[ListImageHandler][processDriver] after sleep"); } catch (Exception e) { System.out.println("[ListImageHandler][processDriver] Exception caught"); } // find all image element List<WebElement> findElements = driver.findElements(By.xpath("//img")); if (url.equals("http://www.vci-classifieds.com/")) { WebElement myDynamicElement = (new WebDriverWait(driver, 10)) .until(ExpectedConditions.presenceOfElementLocated(By.id("searchlist"))); findElements = driver.findElements(By.xpath(".//*[@id='searchlist']/center/table/tbody/tr/td/img")); } System.out.println("[ListImageHandler][processDriver] total Results Found: " + findElements.size()); // show all the links of image for (WebElement elem : findElements) { System.out.println(elem.getAttribute("src")); // System.out.println(elem.toString()); } System.out.println("[ListImageHandler][processDriver] " + findElements.size() + " results shown"); // log outlinks to /tmp/outlinks List<WebElement> findOutlinks = driver.findElements(By.xpath("//a")); try (PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("/tmp/outlinks", true)))) { // this are all the links you like to visit int count = 0; for (WebElement elem : findOutlinks) { out.println(elem.getAttribute("href")); count++; } System.out.println("[ListImageHandler][processDriver] total Outlinks Logged: " + count); } catch (IOException e) { System.err.println(e); } // driver.close(); // System.out.println("[ListImageHandler][processDriver] Close Driver"); }
From source file:org.apache.nutch.protocol.interactiveselenium.handlers.PaginationHandler.java
License:Apache License
private String handle(WebDriver driver, String htmlpage) { for (int i = 0; i < 100; i++) { JavascriptExecutor jse = (JavascriptExecutor) driver; jse.executeScript("window.scrollBy(0,250)"); }/*from w w w . java 2 s . c om*/ try { Thread.sleep(1000); } catch (Exception e) { e.printStackTrace(); } List<WebElement> anchorTags = driver.findElements(By.xpath("//a")); for (WebElement anchorTag : anchorTags) { htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>"; } WebElement ele = driver.findElement(By.className("searchPaginationNext")); while (ele != null) { try { ele.click(); System.out.println(driver.getCurrentUrl()); Thread.sleep(1000); List<WebElement> anchorTags2 = driver.findElements(By.xpath("//*[@id='main']//a")); for (WebElement anchorTag2 : anchorTags2) { htmlpage += "<a href='" + anchorTag2.getAttribute("href") + "'>test</a>"; } ele = driver.findElement(By.className("searchPaginationNext")); for (int i = 0; i < 100; i++) { JavascriptExecutor jse = (JavascriptExecutor) driver; jse.executeScript("window.scrollBy(0,250)"); } try { Thread.sleep(1000); } catch (Exception e) { e.printStackTrace(); } } catch (Exception e) { ele = null; } } htmlpage += "</body></html>"; JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.body.innerHTML=arguments[0]", htmlpage); return htmlpage; }
From source file:org.apache.openmeetings.test.selenium.SeleniumUtils.java
License:Apache License
private static List<WebElement> _findElement(WebDriver driver, String search) { for (By by : _getSearchArray(search)) { try {//from w w w. j a va2 s.c o m List<WebElement> elements = driver.findElements(by); if (elements != null && elements.size() > 0) { return elements; } } catch (Exception e) { // Do not show any warnings } } return null; }
From source file:org.apache.openmeetings.test.selenium.SeleniumUtils.java
License:Apache License
private static boolean checkExists(WebDriver driver, String search) { for (By by : _getSearchArray(search)) { try {/*from ww w. ja v a2 s . com*/ List<WebElement> element = driver.findElements(by); if (element.size() > 0) { return true; } } catch (Exception e) { // Do not show any warnings } } return false; }
From source file:org.apache.portals.pluto.demo.integration.test.ElementEnabled.java
License:Apache License
@Override public WebElement apply(WebDriver webDriver) { WebElement webElement = null;/*from w w w . j a va 2 s . c o m*/ try { List<WebElement> webElements = webDriver.findElements(locator); if (!webElements.isEmpty() && webElements.get(0).isEnabled()) { webElement = webElements.get(0); } } catch (StaleElementReferenceException e) { // Do nothing. } return webElement; }
From source file:org.auraframework.components.ui.autocomplete.AutocompleteUITest.java
License:Apache License
private WebElement getAutoCompleteInput(WebDriver d, int inputNumber) { List<WebElement> inputs = d.findElements(By.cssSelector(INPUT_SELECTOR)); return inputs.get(inputNumber - 1); }