Example usage for org.openqa.selenium By linkText

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

Introduction

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

Prototype

public static By linkText(String linkText) 

Source Link

Usage

From source file:core.Inject.java

License:Apache License

public void injectUntrustedURL_href(String linkText) {
    bar = new commandline.ProgressBar();
    int i = 0, size = _malicious_uris.length;

    for (String current : _malicious_uris) {
        bar.update(i, size);/*from ww  w .  ja  va  2  s  . c o  m*/
        i++;

        if ((numberOfXSS <= limitNumberOfXSS - 1 && Starter.getOperation() == 1)
                || Starter.getOperation() == 2) {

            Starter.inject(current);

            List<WebElement> link = Starter.getDriver().findElements(By.xpath("//a[@href='" + current + "']"));
            List<WebElement> link2 = Starter.getDriver().findElements(By.linkText(linkText));

            for (int j = 0; j < numberOfXSS; j++)
                try {
                    waitForAlert(null);
                } catch (Exception e) {
                    break;
                }

            try {
                if (link.size() != 0 && !link.get(0).getAttribute("href").startsWith("denied")) {
                    link.get(0).click();

                    waitForAlert(current);
                } else if (link2.size() != 0 && !link2.get(0).getAttribute("href").startsWith("denied")
                        && (StringEscapeUtils.unescapeHtml(link2.get(0).getAttribute("href"))
                                .startsWith("javascript")
                                || StringEscapeUtils.unescapeHtml(link2.get(0).getAttribute("href"))
                                        .startsWith("data")
                                || StringEscapeUtils.unescapeHtml(link2.get(0).getAttribute("href"))
                                        .startsWith("feed")
                                || StringEscapeUtils.unescapeHtml(link2.get(0).getAttribute("href"))
                                        .startsWith("vbscript"))) {
                    link2.get(0).click();

                    waitForAlert(current);
                }
            } catch (Exception e) {
                continue;
            }
        }
    }
}

From source file:CucumberSelenium.EncontrarProfissionalCucumberSeleniumTest.java

    _de_uma_empregada_de_limpeza() throws Throwable {
// Write code here that turns the phrase above into concrete actions
        System.out.println("Cucumber.EncontrarProfissionalTest.o_que_preciso__de_uma_empregada_de_limpeza()");

        driver.get(baseUrl + "/encontreJa-1.0/index.html");
        driver.findElement(By.linkText("Encontrar profissional")).click();
        new Select(driver.findElement(By.xpath("//form[@id='searchform']/div/div/div/p/select"))).selectByVisibleText("empregada de limpeza");

        procuraCategoria = "empregada Limpeza";
        category.setName(procuraCategoria);

    }/*from ww w . j a  v  a2 s  . co m*/

From source file:CucumberSelenium.EntrarContactoCucumberSelenium.java

@Dado("^Realizo o meu login$")
public void realizarLogin() throws Throwable {
    driver.findElement(By.linkText("Login")).click();
    driver.findElement(By.id("email")).clear();
    driver.findElement(By.id("email")).sendKeys("afonso@ua.pt");
    driver.findElement(By.id("password")).clear();
    driver.findElement(By.id("password")).sendKeys("1212");
    driver.findElement(By.cssSelector("button.btn.btn-primary")).click();

}

From source file:CucumberSelenium.EntrarContactoCucumberSelenium.java

@Dado("^Eu encontro o profissional na localidade de aveiro$")
public void realizarProcura() throws Throwable {
    driver.findElement(By.linkText("Encontrar profissional")).click();
    new Select(driver.findElement(By.xpath("//form[@id='searchform']/div/div/div/p/select")))
            .selectByVisibleText("empregada de limpeza");
    new Select(driver.findElement(By.name("localidade"))).selectByVisibleText("Aveiro");
    driver.findElement(By.id("submit")).click();
    driver.findElement(By.cssSelector("img")).click();

}

From source file:CucumberSelenium.EntrarContactoCucumberSelenium.java

    o_que_existe_pelo_menos_uma_empregada_com_o_nome_de_maria_amelia() throws Throwable {
    driver.findElement(By.linkText("Entrar em contacto")).click();
    driver.findElement(By.name("horas")).clear();
    driver.findElement(By.name("horas")).sendKeys("1");
    driver.findElement(By.name("horas")).clear();
    driver.findElement(By.name("horas")).sendKeys("0");
    driver.findElement(By.name("horas")).clear();
    driver.findElement(By.name("horas")).sendKeys("1");
    driver.findElement(By.name("horas")).clear();
    driver.findElement(By.name("horas")).sendKeys("2");
    driver.findElement(By.name("horas")).clear();
    driver.findElement(By.name("horas")).sendKeys("3");
    driver.findElement(By.name("horas")).clear();
    driver.findElement(By.name("horas")).sendKeys("4");
    driver.findElement(By.name("horas")).clear();
    driver.findElement(By.name("horas")).sendKeys("5");
    driver.findElement(By.name("horas")).clear();
    driver.findElement(By.name("horas")).sendKeys("6");
    driver.findElement(By.xpath("//section[@id='content']/div/div/form/div/div/textarea")).clear();
    driver.findElement(By.xpath("//section[@id='content']/div/div/form/div/div/textarea")).sendKeys("Preciso do seu contacto");
    driver.findElement(By.id("submit")).click();
}

From source file:cz.zcu.kiv.eegdatabase.ui.RegistrationTestIT.java

License:Apache License

@Test(groups = "web")
public void testEmptyFields() {

    driver.findElement(By.linkText("Register")).click();

    Assert.assertEquals(driver.getTitle(), "Registration");

    driver.findElement(By.xpath("//input[@wicketpath='registration_submit']")).click();
    assertTrue(driver.getPageSource().contains("Field 'Name' is required"));
    assertTrue(driver.getPageSource().contains("Field 'Surname' is required"));
    assertTrue(driver.getPageSource().contains("Field 'E-mail' is required"));
    assertTrue(driver.getPageSource().contains("Field 'Password' is required"));
    assertTrue(driver.getPageSource().contains("Field 'Repeat password' is required"));
    assertTrue(driver.getPageSource().contains("Field 'Control text' is required"));

    Assert.assertEquals(driver.getTitle(), "Registration");
    driver.quit();//from  w  w w . jav a2s  . c  o m

}

From source file:cz.zcu.kiv.eegdatabase.ui.RegistrationTestIT.java

License:Apache License

@Test(groups = "web", enabled = false)
public void testEmailFormat() {

    driver.findElement(By.linkText("Register")).click();
    Assert.assertEquals(driver.getTitle(), "Registration");
    driver.findElement(By.name("name")).sendKeys("testName");
    driver.findElement(By.name("surname")).sendKeys("testSurname");
    driver.findElement(By.name("email")).sendKeys("xxx@seznam");
    driver.findElement(By.name("password")).sendKeys("password");
    driver.findElement(By.name("passwordVerify")).sendKeys("password");

    driver.findElement(By.xpath("//input[@wicketpath='registration_submit']")).click();
    Assert.assertEquals(driver.getTitle(), "Registration");
    assertTrue(driver.getPageSource().contains("is not a valid email address"));

    driver.findElement(By.name("email")).clear();
    driver.findElement(By.name("email")).sendKeys("xxx@seznam.cz");

    driver.findElement(By.xpath("//input[@wicketpath='registration_submit']")).click();
    assertFalse(driver.getPageSource().contains("is not a valid email address"));

    driver.quit();/* w w  w . j a  v  a2  s  . c  o m*/

}

From source file:cz.zcu.kiv.eegdatabase.ui.RegistrationTestIT.java

License:Apache License

@Test(groups = "web", enabled = false)
public void testPasswordVerification() {

    driver.findElement(By.linkText("Register")).click();
    Assert.assertEquals(driver.getTitle(), "Registration");
    driver.findElement(By.name("name")).sendKeys("testName");
    driver.findElement(By.name("surname")).sendKeys("testSurname");
    driver.findElement(By.name("dateOfBirth")).sendKeys("22/11/1998");
    driver.findElement(By.name("email")).sendKeys("xxx@xxx.com");
    driver.findElement(By.name("password")).sendKeys("password");
    driver.findElement(By.name("passwordVerify")).sendKeys("passwordxx");

    driver.findElement(By.xpath("//input[@wicketpath='registration_submit']")).click();
    Assert.assertEquals(driver.getTitle(), "Registration");
    //assertTrue(driver.getPageSource().contains("Inserted passwords don't match."));

    driver.findElement(By.name("password")).clear();
    driver.findElement(By.name("password")).sendKeys("password");
    driver.findElement(By.name("passwordVerify")).clear();
    driver.findElement(By.name("passwordVerify")).sendKeys("password");

    assertFalse(driver.getPageSource().contains("Inserted passwords don't match."));
    driver.findElement(By.xpath("//input[@wicketpath='registration_submit']")).click();

    driver.quit();/*from w  w w  . jav a  2s.co m*/

}

From source file:de.dentrassi.pm.testing.ChannelTester.java

License:Open Source License

/**
 * Upload a file to the channel/*from w ww.jav a2 s  .  c o  m*/
 *
 * @param localFileName
 *            the file to upload
 * @return a set of artifact ids which got created by this operation. This
 *         list may be empty or contain one or more artifacts
 */
public Set<String> upload(final String localFileName) {
    final Set<String> before = getAllArtifactIds();

    get(String.format("/channel/%s/add", this.id));

    final WebElement link = this.context.findElement(By.linkText("Upload"));

    Assert.assertTrue(link.findElement(By.xpath("..")).getAttribute("class").contains("active"));
    ;

    // upload file

    final File input = this.context.getTestFile(localFileName);

    {
        final WebElement ele = this.context.findElement(By.id("file"));
        Assert.assertNotNull(ele);

        ele.sendKeys(input.toString());
        ele.submit();
    }

    final Set<String> after = getAllArtifactIds();

    after.removeAll(before);

    return after;
}

From source file:de.dentrassi.pm.testing.UploadTest.java

License:Open Source License

private void withChannel(final String channelId) {
    driver.get(resolve(String.format("/channel/%s/viewPlain", channelId)));

    // should be an empty channel

    Assert.assertTrue(findArtifacts().isEmpty());

    driver.get(resolve(String.format("/channel/%s/add", channelId)));

    // test for "Upload" active

    final WebElement link = driver.findElement(By.linkText("Upload"));
    Assert.assertTrue(link.findElement(By.xpath("..")).getAttribute("class").contains("active"));
    ;// ww w  . j av  a  2s. c  o m

    // upload file

    final File input = getAbsolutePath("data/test.bundle1-1.0.0-SNAPSHOT.jar");

    {
        final WebElement ele = driver.findElementById("file");
        Assert.assertNotNull(ele);

        ele.sendKeys(input.toString());

        ele.submit();
    }

    // navigate to plain view

    driver.get(resolve(String.format("/channel/%s/viewPlain", channelId)));

    // check upload

    final List<String> arts = findArtifacts();
    Assert.assertEquals(1, arts.size());

    final File file = makeStoreFile(arts.get(0));

    System.out.println("Looking for: " + file);

    Assert.assertTrue(file.exists());
    Assert.assertTrue(file.isFile());
    Assert.assertTrue(file.canRead());
    Assert.assertEquals(input.length(), file.length());
}