Example usage for org.openqa.selenium WebElement getTagName

List of usage examples for org.openqa.selenium WebElement getTagName

Introduction

In this page you can find the example usage for org.openqa.selenium WebElement getTagName.

Prototype

String getTagName();

Source Link

Document

Get the tag name of this element.

Usage

From source file:WebDriverEventHandler.java

License:Open Source License

/**
 * Called before {@link org.openqa.selenium.WebDriver#findElement WebDriver.findElement(...)}, or
 * {@link org.openqa.selenium.WebDriver#findElements WebDriver.findElements(...)}, or {@link org.openqa.selenium.WebElement#findElement
 * WebElement.findElement(...)}, or {@link org.openqa.selenium.WebElement#findElement WebElement.findElements(...)}.
 *
 * @param by//  w  ww  .j  a v a 2s  . co m
 * @param element will be <code>null</code>, if a find method of <code>WebDriver</code> is called.
 * @param driver
 */
@Override
public void beforeFindBy(By by, WebElement element, WebDriver driver) {
    System.out.println("beforeFindBy fired !!" ) ;
    System.out.println(by.toString()) ;
    System.out.println(element.getTagName()) ;
    System.out.println(driver.getPageSource()) ;
}

From source file:WebDriverEventHandler.java

License:Open Source License

/**
 * Called after {@link org.openqa.selenium.WebDriver#findElement WebDriver.findElement(...)}, or
 * {@link org.openqa.selenium.WebDriver#findElements WebDriver.findElements(...)}, or {@link org.openqa.selenium.WebElement#findElement
 * WebElement.findElement(...)}, or {@link org.openqa.selenium.WebElement#findElement WebElement.findElements(...)}.
 *
 * @param by//from   w ww.j a  v a  2s  .  c o  m
 * @param element will be <code>null</code>, if a find method of <code>WebDriver</code> is called.
 * @param driver
 */
@Override
public void afterFindBy(By by, WebElement element, WebDriver driver) {
    System.out.println("afterFindBy fired !!" ) ;
    System.out.println(by.toString()) ;
    System.out.println(element.getTagName()) ;
    System.out.println(driver.getPageSource()) ;
}

From source file:WebDriverEventHandler.java

License:Open Source License

/**
 * Called before {@link org.openqa.selenium.WebElement#click WebElement.click()}.
 *
 * @param element//from w  w w. j a v a 2 s .  c om
 * @param driver
 */
@Override
public void beforeClickOn(WebElement element, WebDriver driver) {
    System.out.println("beforeClickOn fired !!" ) ;
    System.out.println(element.getTagName()) ;
    System.out.println(driver.getPageSource()) ;
}

From source file:WebDriverEventHandler.java

License:Open Source License

/**
 * Called after {@link org.openqa.selenium.WebElement#click WebElement.click()}. Not called, if an exception is
 * thrown./*ww  w.  ja  v a2  s.  c o  m*/
 *
 * @param element
 * @param driver
 */
@Override
public void afterClickOn(WebElement element, WebDriver driver) {
    System.out.println("afterClickOn fired !!" ) ;
    System.out.println(element.getTagName()) ;
    System.out.println(driver.getPageSource()) ;
}

From source file:WebDriverEventHandler.java

License:Open Source License

/**
 * Called before {@link org.openqa.selenium.WebElement#clear WebElement.clear()}, {@link org.openqa.selenium.WebElement#sendKeys
 * WebElement.sendKeys(...)}.//from  w ww .  j  a  v a  2s  .  c  o m
 *
 * @param element
 * @param driver
 */
@Override
public void beforeChangeValueOf(WebElement element, WebDriver driver) {
    System.out.println("beforeChangeValueOf fired !!" ) ;
    System.out.println(element.getTagName()) ;
    System.out.println(driver.getPageSource()) ;
}

From source file:WebDriverEventHandler.java

License:Open Source License

/**
 * Called after {@link org.openqa.selenium.WebElement#clear WebElement.clear()}, {@link org.openqa.selenium.WebElement#sendKeys
 * WebElement.sendKeys(...)}}. Not called, if an exception is thrown.
 *
 * @param element/*from  w  w  w.  java 2  s  .co m*/
 * @param driver
 */
@Override
public void afterChangeValueOf(WebElement element, WebDriver driver) {
    System.out.println("afterChangeValueOf fired !!" ) ;
    System.out.println(element.getTagName()) ;
    System.out.println(driver.getPageSource()) ;
}

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  ww.j a v a 2  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 {/*w  w  w .ja  v a  2  s  .  c  om*/

        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:be.rubus.web.testing.CommonElementCode.java

License:Apache License

protected boolean isHtmlElement(WebElement element, String elementName) {
    return element.getTagName().toUpperCase().equals(elementName);
}

From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.ui.WebAutoComplete.java

License:Open Source License

/**
 * Mtodo generalizado para selecionar o valor da lista
 * //  w ww  . j  a v  a  2  s . c  o  m
 * @param value Valor a ser informado no campo de texto do autocomplete
 */
protected void select(String value) {

    // Aguarda o primeiro elemento ser clicvel
    waitElement(0);

    List<WebElement> elements = getElements();
    if (elements.size() == 1 && getElementMap().locator().length == 1) {
        throw new BehaveException(
                message.getString("exception-autocomplete-missing-elements", "locator", "@ElementMap"));
    }

    WebElement element = elements.get(0);

    if (element.getTagName().equals("input") && element.getAttribute("type").equals("text")) {
        // Preenche o valor do Autocomplete
        element.clear();
        element.sendKeys(value);
    }

    /*
     *  Tempo do efeito de abertura das opes
     *  
     *  Obs: Utilizada API de Reflection para retrocompatibilidade
     *      com verses anteriores do DBehave (1.3.0 por exemplo) 
     */
    try {
        Method waitElementOnlyVisible = getClass().getMethod("waitElementOnlyVisible",
                new Class[] { Integer.class });
        try {
            waitElementOnlyVisible.invoke(this, new Object[] { 1 });
        } catch (IllegalArgumentException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } catch (NoSuchMethodException e) {
        waitElement(1);
    }

    if (this.selectValue != null) {
        value = this.selectValue;
    }

    selectOnList(elements.get(1), value);
}