Example usage for org.openqa.selenium By tagName

List of usage examples for org.openqa.selenium By tagName

Introduction

In this page you can find the example usage for org.openqa.selenium By tagName.

Prototype

public static By tagName(String tagName) 

Source Link

Usage

From source file:TestWithSelenium.java

@Test
public void xTestEdit() {
    //searching for tbody
    List<WebElement> tableRows = (new WebDriverWait(driver, MAX))
            .until((ExpectedCondition<WebElement>) (WebDriver d) -> {
                return d.findElement(By.tagName("tbody"));
            }).findElements(By.tagName("tr"));

    WebElement editButton = null;//from   w  w  w .  ja  va 2 s. c  om
    for (int i = 0; i < tableRows.size(); i++) {
        if (tableRows.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) {
            editButton = tableRows.get(i);
            break;
        }
    }

    editButton.findElements(By.tagName("td")).get(7).findElements(By.tagName("a")).get(0).click();
    WebElement element = driver.findElement(By.id("description"));
    element.clear();
    element.sendKeys("Cool car");
    driver.findElement(By.id("save")).click();

    //searching for new tbody
    List<WebElement> tableRowsUpdated = (new WebDriverWait(driver, MAX))
            .until((ExpectedCondition<WebElement>) (WebDriver d) -> {
                return d.findElement(By.tagName("tbody"));
            }).findElements(By.tagName("tr"));

    String descriptionNew = "";
    for (int i = 0; i < tableRowsUpdated.size(); i++) {
        if (tableRowsUpdated.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) {
            descriptionNew = tableRowsUpdated.get(i).findElements(By.tagName("td")).get(5).getText();
            break;
        }
    }
    assertThat(descriptionNew, is("Cool car"));
}

From source file:TestWithSelenium.java

@Test
public void zAddNew() {
    driver.findElement(By.id("new")).click();
    driver.findElement(By.id("year")).sendKeys("2008");
    driver.findElement(By.id("registered")).sendKeys("2002-5-5");
    driver.findElement(By.id("make")).sendKeys("Kia");
    driver.findElement(By.id("model")).sendKeys("Rio");
    driver.findElement(By.id("description")).sendKeys("As new");
    driver.findElement(By.id("price")).sendKeys("31000");
    driver.findElement(By.id("save")).click();

    WebElement table = (new WebDriverWait(driver, MAX)).until((ExpectedCondition<WebElement>) (WebDriver d) -> {
        return d.findElement(By.tagName("tbody"));
    });/*  w w  w. j a  va  2 s.  c o m*/
    Assert.assertThat(table.findElements(By.tagName("tr")).size(), is(6));

}

From source file:$.ApplicationTestCase.java

License:Apache License

@Test
    @RunAsClient// ww  w  .  j  a  v  a2 s  . c o m
    public void testFoo() {
        driver.get(deploymentURL.toString());
        WebElement body = driver.findElement(By.tagName("body"));
        assertEquals("Hello World", body.getText());
    }

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);/*  w  w  w . j  av  a2  s  . co 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.DrawLevel.java

public static void main(String[] args) throws Exception {
    System.out.println("esto es DrawLevel");
    for (int k = 0; k < URLlist.length; ++k) {
        String URL = URLlist[k];
        String NAME = namefile(URL);

        By by = By.tagName("body");
        s = Selenide.$(by);//from   w  w w.j  a va 2  s  .c  o m

        Document doc = getDoc(URL, true);
        Elements e1 = doc.body().getAllElements();

        ArrayList<String> tags = new ArrayList<>();
        Selenide.screenshot(NAME);

        elements = new ArrayList<>();
        maxj = 0;
        numberElements = e1.size();
        Integer numberSelenideElements = 0;
        System.out.println("number of elements=" + numberElements);
        Integer elementCounter = 0;
        for (Element elem : e1) {
            elementCounter++;
            System.out.println("Examining element '" + elem.nodeName() + "'");
            if (tags.indexOf(elem.tagName()) != -1) {
                System.out.println("Skipping " + elem.tagName());
                continue;
            }
            tags.add(elem.tagName());
            ElementsCollection selenideElements = Selenide.$$(By.tagName(elem.tagName()));
            numberSelenideElements = selenideElements.size();
            System.out.println("number of selenide elements=" + numberSelenideElements);
            int id = 1;
            for (SelenideElement temp2 : selenideElements) {
                System.out.println(
                        id + "/" + numberSelenideElements + "/" + elementCounter + "/" + numberElements);

                processSelenideElement(temp2, elem, id);
                id++;
                //if(id>MAX_DEPTH2){
                //    continue;
                //}
            }
        }

        System.out.println("out of loop");

        PrintWriter writer = new PrintWriter(RESULTS_PATH + NAME + ".txt", "UTF-8");

        for (String temp : elements) {
            writer.println(temp);
        }
        writer.close();

        int[] conteo = new int[maxj];
        for (String temp : elements) {
            String[] aux = temp.split(",");
            conteo[Integer.parseInt(aux[5]) - 1]++;
        }

        int acum = 0;
        double[] acumulado = new double[maxj];
        for (int i = 0; i < conteo.length; ++i) {
            acum += conteo[i];
            acumulado[i] = acum;
        }

        BufferedImage img = null;
        try {
            img = ImageIO.read(new File(PICTURES_PATH + NAME + ".png"));
        } catch (Exception e) {
            System.err.println("Trying to read '" + PICTURES_PATH + NAME + ".png'");
            e.printStackTrace();
            System.exit(1);
        }
        Graphics2D graph = img.createGraphics();
        graph.setColor(Color.RED);
        ArrayList<String> elementsGraphed = new ArrayList<>();

        for (String temp : elements) {
            String[] aux = temp.split(",");
            if (Integer.parseInt(aux[5]) < maxj
                    && conteo[Integer.parseInt(aux[5]) - 1] > conteo[Integer.parseInt(aux[5])]) {
                int x = Integer.parseInt(aux[1]);
                int y = Integer.parseInt(aux[2]);
                int w = Integer.parseInt(aux[3]);
                int h = Integer.parseInt(aux[4]);

                graph.draw(new Rectangle(x, y, w, h));
                elementsGraphed.add(temp);
            }
        }

        graph.dispose();

        //Here it generates the png file
        ImageIO.write(img, "png", new File(RESULTS_PATH + NAME + ".png"));

        System.out.println("DrawLevel terminado");
    }
}

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 .  j  a  v a2 s  . c o 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:akori.FeaturesSelenide.java

public static void main(String[] args) throws Exception {
    System.out.println("esto es FeaturesSelenide");
    PrintWriter writer = new PrintWriter("features.txt", "UTF-8");
    try {//from  ww  w.  j  a  v  a2  s. co m

        String URL = "http://www.mbauchile.cl";

        open(URL);

        SelenideElement s = $(By.tagName("body"));

        Document doc = Jsoup.connect(URL).timeout(0).get();
        Elements e1 = doc.body().getAllElements();

        ArrayList<String> tags = new ArrayList<String>();

        int i = 1;
        for (Element temp : e1) {
            if (tags.indexOf(temp.tagName()) == -1) {
                tags.add(temp.tagName());
                ElementsCollection query = $$(By.tagName(temp.tagName()));
                for (SelenideElement temp2 : query) {
                    WebElement temp1 = temp2.toWebElement();
                    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.print(i + "," + temp1.getTagName() + "," + po.x + "," + po.y + "," + d.width
                                + "," + d.height + "," + temp1.getAttribute("class") + ","
                                + temp1.getAttribute("src"));
                        int j = 1;
                        for (j = 1; !temp2.equals(s); ++j) {
                            temp2 = temp2.parent();
                            if (j > 100)
                                break;
                        }
                        writer.println("," + j);
                    } 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"));
                        int j = 1;
                        for (j = 1; !temp2.equals(s); ++j) {
                            temp2 = temp2.parent();
                            if (j > 100)
                                break;
                        }
                        writer.println("," + j);
                    } else {
                        writer.println(i + "," + temp1.getTagName() + "," + po.x + "," + po.y + "," + d.width
                                + "," + d.height + "," + temp1.getAttribute("class") + "," + temp1.getText());
                        int j = 1;
                        for (j = 1; !temp2.equals(s); ++j) {
                            temp2 = temp2.parent();
                            if (j > 100)
                                break;
                        }
                        writer.println("," + j);
                    }
                    ++i;

                }
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    writer.close();
}

From source file:app.Stepdefs.java

@Given("^Edit is pressed for key \"([^\"]*)\"$")
public void edit_is_pressed_for_key(String key) throws Throwable {
    // let's get all the <td> -elements from HTML
    List<WebElement> lista = driver.findElements(By.tagName("td"));
    int indeksi = 0;
    for (int i = 0; i < lista.size(); i++) {
        WebElement element = lista.get(i); // there are four columns: checkbox, reference, tags, edit 
        if (element.getText().contains(key)) {
            indeksi = i + 2; // element + 2 -> get the edit -element 
            break;
        }//from   w w w.  ja  v a2 s.c o  m
    }
    if (indeksi > 0) { // let's press the founded EDIT button (submit doesn't work)
        lista.get(indeksi).click();
    }
    Thread.sleep(2000);
}

From source file:app.Stepdefs.java

@Given("^number of displayed references is calculated$")
public void number_of_displayed_references_is_calculated() throws Throwable {
    amount1 = driver.findElements(By.tagName("td")).size();
}

From source file:app.Stepdefs.java

@When("^number of displayed references is calculated again$")
public void number_of_displayed_references_is_calculated_again() throws Throwable {
    amount2 = driver.findElements(By.tagName("td")).size();
}