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:app.Stepdefs.java

@When("^link tag by name \"([^\"]*)\" is pressed$")
public void link_tag_by_name_is_pressed(String tag) throws Throwable {
    List<WebElement> lista = driver.findElements(By.tagName("span"));
    for (WebElement element : lista) {
        if (element.getText().contains(tag)) {
            element.click();/*w  w w  . ja va 2 s  . c  o  m*/
        }
    }
    Thread.sleep(2000);
}

From source file:application.Main.java

License:Open Source License

public static void appSingleThread(Globals GLOBALS) {
    LinkedList<String> list = Input.readFacebookPostIds(GLOBALS.FILENAME);
    if (GLOBALS.RANDOM) {
        Collections.shuffle(list);
    }/*from   w  w  w  .  j a  v  a 2 s  . c o  m*/
    String email = GLOBALS.fb_eamil;
    String pass = GLOBALS.password;
    WebDriver driver = new FirefoxDriver(); // The Firefox driver supports javascript 
    Autenticate.perform(driver, email, pass);
    try {
        Thread.sleep(Globals.TIME_TO_LOGIN_IN_FB_MS);
    } catch (Exception ex) {
        System.out.println("InterruptedException in crawl.run()");
        ex.printStackTrace();
        System.exit(-1);
    }
    for (String post_id : list) {
        System.out.println("\n****** STARTING NEW TREE: " + post_id + "******");
        try {
            //OPEN NEW TAB
            WebElement body = driver.findElement(By.tagName("body"));
            body.sendKeys(Keys.CONTROL + "t");
            Tree post = new Tree(post_id, GLOBALS);
            boolean result = post.crawl(driver);
            if (result) {
                post.prune();
                post.print();
                post.printEdgeList();
                System.out.println("****** TREE " + post_id + " ACCOMPLISHED ******");
            } else {
                body.sendKeys(Keys.CONTROL + "w");
                System.out.println("****** TREE " + post_id + " FAILED ******");
            }
            //SWITCH TAB
            ArrayList<String> tabs = new ArrayList<String>(driver.getWindowHandles());
            driver.switchTo().window(tabs.get(tabs.size() - 1));
        } catch (Exception e) {
            System.out.println("****** TREE " + post_id + " FAILED ******");
            System.out.println("EXCEPTION in MAIN " + e);
            System.out.println("...RESTARTING APPLICATION AFTER 1 minute APPLICATION...");
            driver.quit();
            try {
                Thread.sleep(Globals.ONE_MINUTE);
            } catch (Exception ex) {
                System.out.println("InterruptedException in crawl.run()");
                ex.printStackTrace();
                System.exit(-1);
            }
            driver = new FirefoxDriver(); // The Firefox driver supports javascript 
            Autenticate.perform(driver, email, pass);
        }
    }
    driver.quit();
}

From source file:at.tugraz.ist.cucumber.SeleniumStepdefs.java

License:Open Source License

@When("^I change the language to \"([^\"]*)\"$")
public void I_change_the_language_to(String language) throws Throwable {
    WebElement select = driver().findElement(By.id("switchLanguage"));
    List<WebElement> options = select.findElements(By.tagName("option"));
    for (WebElement option : options) {
        if (option.getText().contains(language)) {
            option.click();/*from ww  w  .  j a va 2 s  .  com*/
            blur(By.id("switchLanguage"));
            break;
        }
    }
    jqueryWait();
}

From source file:automation.HE.java

@After
public void tearDown() throws Exception {
    try {/*from www .j av a  2 s  .co m*/
        //         result = driver.findElement(By.cssSelector(cssSelector)).getAttribute("innerHTML");
        result = "";
        WebElement table = driver.findElement(By.cssSelector(cssSelector));
        //         System.out.println("1" + table.getAttribute("innerHTML"));
        //         System.out.println("table:" + table.html());
        List<WebElement> rows = table.findElements(By.tagName("tr"));
        //         System.out.println("2");
        for (WebElement row : rows) {
            for (WebElement cell : row.findElements(By.tagName("td"))) {
                result += cell.getText().trim() + "\t";
            }
            result += "\n";
            //            System.out.println(result);
            //            System.out.println("------");
        }
        System.out.println(result);

    } catch (Exception e) {
        Logger.getLogger(BT.class.getName()).log(Level.SEVERE, null, e);
    } finally {

        super.store();

        driver.quit();
        String verificationErrorString = verificationErrors.toString();
        if (!"".equals(verificationErrorString)) {
            fail(verificationErrorString);
        }
    }
}

From source file:automation.PCCWGlobalcom.java

@After
public void tearDown() throws Exception {
    Thread.sleep(60 * 1000);/* w w  w. java 2  s . c o  m*/
    try {
        WebElement resultElement = driver.findElement(By.id("test_results"));
        List<WebElement> rows = resultElement.findElements(By.tagName("tr"));
        for (WebElement row : rows) {
            result += row.getText().trim() + "\n";

        }
        System.out.println(result);

        //         result = resultElement.getAttribute("innerHTML");
        //         result = result.replaceAll("[\u0000-\u0008]", "");
        //         result = result.replaceAll("[\u000B-\u001f]", "");
        //         result = replaceBrTag(result);
        //         result = removeTags(result);
        //         result = replaceHtmlString(result);
    } catch (Exception e) {
        Logger.getLogger(BT.class.getName()).log(Level.SEVERE, null, e);
    } finally {
        super.store();
        driver.quit();
        String verificationErrorString = verificationErrors.toString();
        if (!"".equals(verificationErrorString)) {
            fail(verificationErrorString);
        }
    }
}

From source file:backend.MakeUserTest.java

@Test(description = "check if new user was succesfully added", priority = 3, dependsOnMethods = { "makeUser" })
public void validateNewUser() throws InterruptedException {
    WebDriverWait wait = new WebDriverWait(driver, 10);
    //sort descending(newest on top)
    WebElement table = driver.findElement(By.id("detailTable_person"));
    WebElement idCell = table.findElement(By.xpath("//th[text()='Id']"));
    idCell.click();//from w w w  .  j a va 2s  . c om
    Thread.sleep(500);

    //select first table entry
    List<WebElement> tableRows = table.findElements(By.tagName("tr"));
    String userId = tableRows.get(2).findElement(By.xpath("//td[1]")).getText();
    String nameCell = tableRows.get(2).findElement(By.xpath("//td[2]")).getText();

    //validate if first entry is the new user. delete user if true, fails test if false
    if (nameCell.equals("testUser123")) {
        WebElement delete = table.findElement(By.xpath("//span[@onclick=\"dialog.deleteDialog('" + userId
                + "','person',{ refresh : 'null'}, null)\"]"));
        delete.click();
        WebElement elementConfirm = wait
                .until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[text()='Delete']")));
        WebElement confirm = table.findElement(By.xpath("//span[text()='Delete']"));
        confirm.click();
        WebElement elementButton = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(
                "//span[@onclick=\"dialog.formDialog(null,'person', { refresh : 'detailTable_person'}, {})\"]")));
    } else {
        org.testng.Assert.fail("Test user was not succesfully created.");
    }
}

From source file:be.rubus.web.jerry.initializer.RequiredInitializerTest.java

License:Apache License

@Test
@RunAsClient/*  w  ww .j  a va  2  s.  c  om*/
public void testRequired() throws Exception {
    driver.get(new URL(contextPath, "validations.xhtml").toString());

    WebElement submitButton = driver.findElement(By.id("test:submit"));
    submitButton.click();

    Thread.sleep(1000);

    WebElement messages = driver.findElement(By.id("messages"));
    List<WebElement> errorElements = messages.findElements(By.tagName("li"));
    assertThat(errorElements).hasSize(1);

    assertThat(errorElements.get(0).getText()).contains("Validation Error: Value is required.");

}

From source file:be.rubus.web.jerry.recording.RecordValueTest.java

License:Apache License

@Test
@RunAsClient/*from  www . j  a  v  a2  s  .co m*/
public void testClassLevelValidation() throws Exception {
    driver.get(new URL(contextPath, "dateRange.xhtml").toString());

    WebElement field = driver.findElement(By.id("test:beginDate"));
    field.sendKeys("01/03/2015");

    field = driver.findElement(By.id("test:endDate"));
    field.sendKeys("01/01/2015");

    WebElement submitButton = driver.findElement(By.id("test:submit"));
    submitButton.click();

    Thread.sleep(1000);

    WebElement messages = driver.findElement(By.id("errors"));
    List<WebElement> errorElements = messages.findElements(By.tagName("li"));

    // FIXME The test fails and it seems that RecordingInfoPhaseListener doesn't kick in
    assertThat(errorElements).hasSize(1);

    assertThat(errorElements.get(0).getText()).contains("Validation Error: Value is required.");

}

From source file:be.rubus.web.jerry.validation.FutureDateProviderTest.java

License:Apache License

@Test
@RunAsClient/*ww w . ja v a 2 s  . c o  m*/
public void testFuture() throws Exception {
    driver.get(new URL(contextPath, "future.xhtml").toString());

    //By default, the date provider is using system date, so failures
    WebElement date1 = driver.findElement(By.id("test:date1"));
    date1.sendKeys("23/02/2015");

    WebElement date2 = driver.findElement(By.id("test:date2"));
    date2.sendKeys("23/02/2015");

    assertThat(date1.getAttribute("class")).doesNotContain("ui-state-error");
    assertThat(date2.getAttribute("class")).doesNotContain("ui-state-error");

    WebElement btn = driver.findElement(By.id("test:submit"));
    btn.click();

    WebElement errors = driver.findElement(By.id("errors"));

    List<WebElement> errorMessages = errors.findElements(By.tagName("li"));
    assertThat(errorMessages).hasSize(2);

    // Page is reloaded so elements are detached

    date1 = driver.findElement(By.id("test:date1"));
    date2 = driver.findElement(By.id("test:date2"));

    assertThat(date1.getAttribute("class")).contains("ui-state-error");
    assertThat(date2.getAttribute("class")).contains("ui-state-error");

    // Set date for DateProvider
    WebElement fixedNow = driver.findElement(By.id("date:fixedNow"));
    fixedNow.clear();
    fixedNow.sendKeys("20/02/2015");

    WebElement dateBtn = driver.findElement(By.id("date:setDate"));
    dateBtn.click();

    date1 = driver.findElement(By.id("test:date1"));
    date1.sendKeys("23/02/2015");

    date2 = driver.findElement(By.id("test:date2"));
    date2.sendKeys("23/02/2015");

    btn = driver.findElement(By.id("test:submit"));
    btn.click();

    errors = driver.findElement(By.id("errors"));

    errorMessages = errors.findElements(By.tagName("li"));
    assertThat(errorMessages).hasSize(1); // Only 1 error now

    // Page is reloaded so elements are detached

    date1 = driver.findElement(By.id("test:date1"));
    date2 = driver.findElement(By.id("test:date2"));

    assertThat(date1.getAttribute("class")).contains("ui-state-error");
    assertThat(date2.getAttribute("class")).doesNotContain("ui-state-error"); // The one withValFuture

}

From source file:be.rubus.web.jerry.validation.FutureTest.java

License:Apache License

@Test
@RunAsClient//  www  .  ja va  2s. c  o  m
public void testFuture() throws Exception {
    driver.get(new URL(contextPath, "future_NoProvider.xhtml").toString());

    WebElement date1 = driver.findElement(By.id("test:date1"));
    date1.sendKeys("23/02/2015");

    WebElement date2 = driver.findElement(By.id("test:date2"));
    date2.sendKeys("23/02/2015");

    WebElement btn = driver.findElement(By.id("test:submit"));
    btn.click();

    WebElement errors = driver.findElement(By.id("errors"));

    List<WebElement> errorMessages = errors.findElements(By.tagName("li"));
    assertThat(errorMessages).hasSize(2);

    // Page is reloaded so elements are detached

    date1 = driver.findElement(By.id("test:date1"));
    date2 = driver.findElement(By.id("test:date2"));

    assertThat(date1.getAttribute("class")).contains("ui-state-error");
    assertThat(date2.getAttribute("class")).contains("ui-state-error");
}