List of usage examples for org.openqa.selenium WebDriver findElements
@Override List<WebElement> findElements(By by);
From source file:WaitTool.java
License:Open Source License
/** * Wait for the List<WebElement> to be present in the DOM, regardless of being displayed or not. * Returns all elements within the current page DOM. * * @param WebDriver The driver object to be used * @param By selector to find the element * @param int The time in seconds to wait until returning a failure * * @return List<WebElement> all elements within the current page DOM, or null (if the timeout is reached) *//*from ww w . ja v a2s.c om*/ public static List<WebElement> waitForListElementsPresent(WebDriver driver, final By by, int timeOutInSeconds) { List<WebElement> elements; try { driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait() WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds); wait.until((new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver driverObject) { return areElementsPresent(driverObject, by); } })); elements = driver.findElements(by); driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_PAGE, TimeUnit.SECONDS); //reset implicitlyWait return elements; //return the element } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:WaitTool.java
License:Open Source License
/** * Checks if the List<WebElement> are in the DOM, regardless of being displayed or not. * * @param driver - The driver object to use to perform this element search * @param by - selector to find the element * @return boolean/*from w w w .ja v a 2 s . c o m*/ */ private static boolean areElementsPresent(WebDriver driver, By by) { try { driver.findElements(by); return true; } catch (NoSuchElementException e) { return false; } }
From source file:akori.AKORI.java
public static void main(String[] args) throws IOException, InterruptedException { System.out.println("esto es AKORI"); URL = "http://www.mbauchile.cl"; PATH = "E:\\NetBeansProjects\\AKORI\\"; NAME = "mbauchile.png"; // Extrar DOM tree Document doc = Jsoup.connect(URL).timeout(0).get(); // The Firefox driver supports javascript WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); System.out.println(driver.manage().window().getSize().toString()); System.out.println(driver.manage().window().getPosition().toString()); int xmax = driver.manage().window().getSize().width; int ymax = driver.manage().window().getSize().height; // Go to the URL page driver.get(URL);/* www . ja v a 2 s. c o m*/ File screen = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(screen, new File(PATH + NAME)); BufferedImage img = ImageIO.read(new File(PATH + NAME)); //Graphics2D graph = img.createGraphics(); BufferedImage img1 = new BufferedImage(xmax, ymax, BufferedImage.TYPE_INT_ARGB); Graphics2D graph1 = img.createGraphics(); double[][] matrix = new double[ymax][xmax]; BufferedReader in = new BufferedReader(new FileReader("et.txt")); String linea; double max = 0; graph1.drawImage(img, 0, 0, null); HashMap<String, Integer> lista = new HashMap<String, Integer>(); int count = 0; for (int i = 0; (linea = in.readLine()) != null && i < 10000; ++i) { String[] datos = linea.split(","); int x = (int) Double.parseDouble(datos[0]); int y = (int) Double.parseDouble(datos[2]); long time = Double.valueOf(datos[4]).longValue(); if (x >= xmax || y >= ymax) continue; if (time < 691215) continue; if (time > 705648) break; if (lista.containsKey(x + "," + y)) lista.put(x + "," + y, lista.get(x + "," + y) + 1); else lista.put(x + "," + y, 1); ++count; } System.out.println(count); in.close(); Iterator iter = lista.entrySet().iterator(); Map.Entry e; for (String key : lista.keySet()) { Integer i = lista.get(key); if (max < i) max = i; } System.out.println(max); max = 0; while (iter.hasNext()) { e = (Map.Entry) iter.next(); String xy = (String) e.getKey(); String[] datos = xy.split(","); int x = Integer.parseInt(datos[0]); int y = Integer.parseInt(datos[1]); matrix[y][x] += (int) e.getValue(); double aux; if ((aux = normalMatrix(matrix, y, x, ((int) e.getValue()) * 4)) > max) { max = aux; } //normalMatrix(matrix,x,y,20); if (matrix[y][x] > max) max = matrix[y][x]; } int A, R, G, B, n; for (int i = 0; i < xmax; ++i) { for (int j = 0; j < ymax; ++j) { if (matrix[j][i] != 0) { n = (int) Math.round(matrix[j][i] * 100 / max); R = Math.round((255 * n) / 100); G = Math.round((255 * (100 - n)) / 100); B = 0; A = Math.round((255 * n) / 100); ; if (R > 255) R = 255; if (R < 0) R = 0; if (G > 255) G = 255; if (G < 0) G = 0; if (R < 50) A = 0; graph1.setColor(new Color(R, G, B, A)); graph1.fillOval(i, j, 1, 1); } } } //graph1.dispose(); ImageIO.write(img, "png", new File("example.png")); System.out.println(max); graph1.setColor(Color.RED); // Extraer elementos Elements e1 = doc.body().getAllElements(); int i = 1; ArrayList<String> tags = new ArrayList<String>(); for (Element temp : e1) { if (tags.indexOf(temp.tagName()) == -1) { tags.add(temp.tagName()); List<WebElement> query = driver.findElements(By.tagName(temp.tagName())); for (WebElement temp1 : query) { Point po = temp1.getLocation(); Dimension d = temp1.getSize(); if (d.width <= 0 || d.height <= 0 || po.x < 0 || po.y < 0) continue; System.out.println(i + " " + temp.nodeName()); System.out.println(" x: " + po.x + " y: " + po.y); System.out.println(" width: " + d.width + " height: " + d.height); graph1.draw(new Rectangle(po.x, po.y, d.width, d.height)); ++i; } } } graph1.dispose(); ImageIO.write(img, "png", new File(PATH + NAME)); driver.quit(); }
From source file:akori.Features.java
public static void main(String[] args) throws IOException, InterruptedException { URL = "http://www.mbauchile.cl"; Document doc = Jsoup.connect(URL).timeout(0).get(); WebDriver driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get(URL);//from w w w . ja v a2 s . co m Elements e1 = doc.body().getAllElements(); Element e = doc.body(); PrintWriter writer = new PrintWriter("features.txt", "UTF-8"); int i = 1; // String[][] matrix = new String[e1.size()][10]; // traverse(e, 1, 1, "", 1, writer, driver); ArrayList<String> tags = new ArrayList<String>(); System.out.println(""); // for (Element temp : e1) { // if (!temp.nodeName().equals("br")) { // writer.println(i + "," + temp.hashCode() + "," + temp.nodeName() + "," + temp.id()); // //System.out.println(i+","+temp.hashCode()+","+temp.nodeName()); // ++i; // } // } i = 1; for (Element temp : e1) { if (tags.indexOf(temp.tagName()) == -1) { tags.add(temp.tagName()); List<WebElement> query = driver.findElements(By.tagName(temp.tagName())); for (WebElement temp1 : query) { Point po = temp1.getLocation(); Dimension d = temp1.getSize(); if (d.width <= 0 || d.height <= 0 || po.x < 0 || po.y < 0) { continue; } if (temp1.getTagName().equals("img")) writer.println(i + "," + temp1.getTagName() + "," + po.x + "," + po.y + "," + d.width + "," + d.height + "," + temp1.getAttribute("class") + "," + temp1.getAttribute("src")); else if (temp1.getTagName().equals("a")) writer.println(i + "," + temp1.getTagName() + "," + po.x + "," + po.y + "," + d.width + "," + d.height + "," + temp1.getAttribute("class") + "," + temp1.getAttribute("href")); else writer.println(i + "," + temp1.getTagName() + "," + po.x + "," + po.y + "," + d.width + "," + d.height + "," + temp1.getAttribute("class") + "," + temp1.getText()); ++i; } } } driver.quit(); writer.close(); }
From source file:applango.common.services.Applango.genericApplangoWebsiteActions.java
private static void clickOnRecordInTable(WebDriver driver1, WebDriverWait wait) throws IOException { driver1.findElements(By.cssSelector(applangoObject.USERTABLER.getValue())).get(0).click(); waitForHistogramToLoad(wait);/*from w w w.java 2 s . c om*/ }
From source file:applango.common.services.Applango.genericApplangoWebsiteActions.java
public static void clickOnRecordInTable(WebDriver driver1, WebDriverWait wait, int recordNumber) throws IOException { // driver1.findElements(By.cssSelector("#usertabler tr")).get(recordNumber).click(); driver1.findElements(By.cssSelector(applangoObject.USERTABLER.getValue())).get(recordNumber).click(); waitForHistogramToLoad(wait);/* ww w . jav a 2s . c o m*/ }
From source file:applango.common.services.Applango.genericApplangoWebsiteActions.java
public static int getNumberOfUsersInList(WebDriver driver) throws IOException { //The number of users will calculate by size of user table / 33 (33 is the size of each column in table) // return driver.findElement(By.id(applangoObject.USERTABLE.getValue().toString())).getSize().getHeight() / 33; return driver.findElements(By.cssSelector(applangoObject.USERTABLER.getValue())).size(); }
From source file:au.unick.testing.oos.lazylocators.BaseLazyLocator.java
License:Apache License
/** * Create and return list of WebElement available from WebDriver by locator * @param wd//from ww w . jav a2 s . c om * @return */ public List<WebElement> getElements(WebDriver wd) { WebElement parentWebElement = getParentElement(wd); By by = by(); if (null == by) { return null; // shall it return parent element in this case? Arrays.asList( parentWebElement ); } if (null == parentWebElement) { return wd.findElements(by); } else { return parentWebElement.findElements(by); } }
From source file:be.ugent.mmlab.webdriver.Demo.java
License:Apache License
public void demoTime() throws InterruptedException { // initialize web browser. WebDriver driver = new FirefoxDriver(); // go to the Belgian railways website driver.get("http://www.belgianrail.be"); // select "English" // HTML://from www .ja v a 2 s . c om // <a // id="ctl00_bodyPlaceholder_languagesList_ctl02_languageNameLink" // href="javascript:__doPostBack('ctl00$bodyPlaceholder$languagesList$ctl02$languageNameLink','')" // > English </a> WebElement english = driver .findElement(By.id("ctl00_bodyPlaceholder_languagesList_ctl02_languageNameLink")); english.click(); // fill out departure WebElement from = driver.findElement(By.id("departureStationInput")); from.sendKeys("Gent-Dampoort"); // pause for a second to make it not too fast Thread.sleep(1000); // click in the field to get the auto-completion away from.click(); // fill out arrival WebElement to = driver.findElement(By.id("arrivalStationInput")); to.sendKeys("Brussel-Noord"); Thread.sleep(1000); to.click(); // click timetable button WebElement timetableButton = driver.findElement(By.id( "ctl00_ctl00_bodyPlaceholder_bodyPlaceholder_mobilityTimeTableSearch_HomeTabTimeTable1_submitButton")); timetableButton.click(); // get departure info // HTML: // <td headers="hafasOVTimeOUTWARD" class="time"> // <div> // <div class="planed overviewDep"> // 10:00 dep <span class="bold prognosis">+12 min.</span> // </div> // <div class="planed"> // 11:20 arr <span class="bold green">+0 min.</span> // </div> // </div> // </td> List<WebElement> timeCells = driver.findElements(By.className("time")); for (WebElement timeCell : timeCells) { List<WebElement> times = timeCell.findElements(By.className("planed")); System.out.println("----------------------------------------------"); System.out.println("departure time: " + times.get(0).getText()); System.out.println("arrival time: " + times.get(1).getText()); } }
From source file:beseenium.model.action.findElementsBy.FindElementsByClass.java
License:Open Source License
/** * performs the find elements by class action. * @param n the index of the element to find information on, i.e. if 3 results are found * the 0 will be the first element 1 the second and so on. will get an array out of bounds. * If you wish the action to return all of the results found then set n = -1. * @return String representation of the returnParam set in the ActionData object * passed into the constructor./*w w w. j a va 2 s . c om*/ * @throws ActionDataException */ @Override public String execute(int n) throws ActionDataException { String searchParam = super.context.getInputParam(); WebDriver browser = super.context.getDriver(); List<WebElement> htmlElements = browser.findElements(By.className(searchParam)); super.context.setElement(htmlElements); return FormatOutput.formatFindElementOutput(htmlElements, n); }