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:de.knowwe.uitest.DiaFluxUITest.java

License:Open Source License

private void createNextFlow() {
    new WebDriverWait(getDriver(), 5)
            .until(ExpectedConditions.presenceOfElementLocated(By.linkText("Click here to create one.")))
            .click();/*from w  w w.j a  v a2s. co  m*/
}

From source file:de.learnlib.alex.data.entities.actions.web.ClickLinkAction.java

License:Apache License

@Override
public ExecuteResult execute(WebSiteConnector connector) {
    final WebElementLocator nodeWithVariables = new WebElementLocator(insertVariableValues(node.getSelector()),
            node.getType());//w  w  w . jav  a 2 s .com

    try {
        final String linkText = getValueWithVariableValues();

        final WebElement element = connector.getElement(nodeWithVariables).findElement(By.linkText(linkText));

        element.click();

        LOGGER.info(LoggerMarkers.LEARNER, "Clicked on link '{}'.", value);
        return getSuccessOutput();
    } catch (Exception e) {
        LOGGER.info(LoggerMarkers.LEARNER, "Could not click on link '{}'.", value, e);
        return getFailedOutput();
    }
}

From source file:de.learnlib.alex.data.entities.actions.web.ClickLinkActionTest.java

License:Apache License

@Test
public void shouldReturnOKIfLinkCouldBeClicked() {
    WebElement body = mock(WebElement.class);
    WebElement fooLink = mock(WebElement.class);

    given(webSiteConnector.getElement(action.getNode())).willReturn(body);
    given(body.findElement(By.linkText(action.getValue()))).willReturn(fooLink);

    assertTrue(action.executeAction(connectors).isSuccess());
    verify(fooLink).click();//from   ww w  .j  av a2  s  .  c  o  m
}

From source file:de.learnlib.alex.data.entities.actions.web.ClickLinkActionTest.java

License:Apache License

@Test
public void shouldReturnFailedIfLinkCouldNotBeClicked() {
    WebElement body = mock(WebElement.class);

    given(webSiteConnector.getElement(action.getNode())).willReturn(body);

    when(body.findElement(By.linkText("Click Me"))).thenThrow(new NoSuchElementException(""));

    assertFalse(action.executeAction(connectors).isSuccess());
}

From source file:de.tklerx.run.ResEntries.java

License:Open Source License

private static void processPlayer(Player p) throws InterruptedException {
    if (!p.getHistory().isEmpty()) {
        return;/*from w w w.j  a  v a  2 s  . c o  m*/
    }
    System.out.println("Processing player " + p.getPlayerName());
    System.out.println(p);
    driver.get(p.getTeamLink());
    Thread.sleep(CLICK_WAIT_TIME);
    List<WebElement> herrenList = driver.findElements(By.linkText("Herren"));
    for (WebElement possibleLink : herrenList) {
        String link = possibleLink.getAttribute("href");
        if (link != null) {
            driver.get(link);
            WebElement temp = driver.findElement(By.linkText(p.getPlayerName()));
            temp.click();
            Thread.sleep(CLICK_WAIT_TIME);
            SimpleDateFormat sd = new SimpleDateFormat("dd.MM.yyyy");
            String dt = sd.format(p.getResDate());
            List<WebElement> checkboxes = driver.findElements(By.xpath("//input[@type=\"checkbox\"]"));
            // System.out.println("Size of checkboxes = " +
            // checkboxes.size());
            for (WebElement checkbox : checkboxes) {
                if (checkbox.getAttribute("name").contains(".15")) {
                    System.out.println(checkbox.getAttribute("name"));
                    checkbox.click();
                }
            }

            WebElement dateField = driver
                    .findElement(By.xpath("//input[@type=\"text\" and @maxlength=\"10\"]"));
            dateField.sendKeys(dt);
            WebElement insertButton = driver
                    .findElement(By.xpath("//input[@type=\"submit\" and @value=\"Einfgen\"]"));
            insertButton.click();
            Thread.sleep(CLICK_WAIT_TIME);
            WebElement confirmButton = driver
                    .findElement(By.xpath("//input[@type=\"submit\" and @value=\"bernehmen\"]"));
            confirmButton.click();
            Thread.sleep(CLICK_WAIT_TIME);
            WebElement nextButton = driver
                    .findElement(By.xpath("//input[@type=\"submit\" and @value=\"Weiter >>\"]"));
            nextButton.click();
            Thread.sleep(CLICK_WAIT_TIME);
            nextButton = driver.findElement(By.xpath("//input[@type=\"submit\" and @value=\"Weiter >>\"]"));
            nextButton.click();
            Thread.sleep(CLICK_WAIT_TIME);
            WebElement textField = driver.findElement(By.name("newWorkflowRemarks"));
            textField.sendKeys("RES 5x: " + p.getPlayerName());
            WebElement saveButton = driver
                    .findElement(By.xpath("//input[@type=\"submit\" and @value=\"Speichern\"]"));
            saveButton.click();
            Thread.sleep(CLICK_WAIT_TIME);
            driver.findElement(By.linkText("Zurck zur bersichtsseite...")).click();
            Thread.sleep(CLICK_WAIT_TIME);
            driver.findElement(By.linkText("Zurck zur Einstiegsseite...")).click();
            Thread.sleep(CLICK_WAIT_TIME);
            break;
        }
        // break;
    }
    return;
}

From source file:de.tntinteractive.portalsammler.sources.HanVBSourceV1.java

License:Open Source License

@Override
public Pair<Integer, Integer> poll(final SourceSettings settings, final UserInteraction gui,
        final SecureStore store) throws Exception {
    final WebDriver driver = this
            .createDriver("https://www.hannoversche-volksbank.de/ptlweb/WebPortal?bankid=0744");

    final WebElement userField = driver.findElement(By.id("vrkennungalias"));
    userField.sendKeys(settings.get(USER, gui));

    final WebElement passwordField = driver.findElement(By.id("pin"));
    passwordField.sendKeys(settings.get(PASSWORD, gui));

    passwordField.submit();/* ww w.  j  a v  a  2  s.c  o m*/

    waitForPresence(driver, By.linkText("Postkorb"));

    int newDocs = 0;
    int knownDocs = 0;
    try {
        clickLink(driver, "Postkorb");
        waitForPresence(driver, By.name("confirmDeleteMultiMessage"));

        final WebElement form = driver.findElement(By.name("confirmDeleteMultiMessage"));
        final WebElement tbody = form.findElement(By.tagName("tbody"));

        final List<String> links = new ArrayList<String>();
        for (final WebElement tr : tbody.findElements(By.tagName("tr"))) {
            final List<WebElement> tds = tr.findElements(By.tagName("td"));
            final WebElement link = tds.get(2).findElement(By.tagName("a"));
            links.add(link.getAttribute("href"));
        }

        for (final String link : links) {
            driver.get(link);

            final DocumentInfo info = DocumentInfo.create(this.getId(), DocumentFormat.TEXT);
            final StringBuilder content = new StringBuilder();

            driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
            final WebElement fieldset = driver.findElement(By.tagName("fieldset"));
            for (final WebElement div : fieldset.findElements(By.tagName("div"))) {
                if (this.isLabeled(div, "Eingang")) {
                    info.setDate(this.parseTimestamp(div.findElement(By.className("gad-field-box")).getText()));
                } else if (this.isLabeled(div, "Betreff")) {
                    final WebElement data = div.findElement(By.className("gad-field-box"));
                    info.addKeywords(data.findElement(By.tagName("span")).getAttribute("title"));
                } else if (this.isNotLabeled(div)) {
                    content.append(div.getText());
                }
            }
            driver.manage().timeouts().implicitlyWait(WAIT_TIME, TimeUnit.SECONDS);

            if (!store.containsDocument(info)) {
                store.storeDocument(info, content.toString().getBytes("UTF-8"));
                newDocs++;
            } else {
                knownDocs++;
            }
        }

    } finally {
        clickLink(driver, "Logout");
    }
    return Pair.of(newDocs, knownDocs);
}

From source file:dk.netarkivet.systemtest.functional.DomainsPageTest.java

License:Open Source License

@Test(groups = { "guitest", "functest" })
public void domainCreationTest() throws Exception {
    addDescription("Tests that domains can be created correctly.");
    addStep("Click the 'Create domain' link in the left menu under the " + "'Definitions' section",
            "The domain creation page should load");
    driver.findElement(By.linkText("Definitions")).click();
    driver.findElement(By.linkText("Create Domain")).click();
    driver.findElement(By.cssSelector("input[type=\"submit\"]"));
    NASAssert.assertTrue(driver.getPageSource().contains("Enter the domain or list of domains to be created"),
            "Domain creation page not loaded correctly");

    addStep("Add a domain to the list of domains to be created and click create.",
            "The created domain should now be displayed");
    String domain1ID = createDomainID();
    driver.findElement(By.name("domainlist")).sendKeys(domain1ID + "\n");
    driver.findElement(By.cssSelector("input[type=\"submit\"]")).click();
    NASAssert.assertTrue(driver.getPageSource().contains("Edit domain"), "Domain page not loaded correctly");

    addStep("Goto the 'Find domain' page and search for the newly added domain", "The domain should be found");
    PageHelper.gotoPage(PageHelper.MenuPages.FindDomains);
    driver.findElement(By.name("DOMAIN_QUERY_STRING")).sendKeys(domain1ID);
    driver.findElement(By.cssSelector("input[type=\"submit\"]")).click();

    NASAssert.assertTrue(driver.getPageSource().contains("Searching for '" + domain1ID + "' returned 1 hits:"),
            "New domain not found.");
}

From source file:dk.netarkivet.systemtest.functional.DomainsPageTest.java

License:Open Source License

@Test(groups = { "guitest", "functest" })
public void usedSeedListsFilteringTest() {
    addDescription(/*  w  w  w  .  j a v a2  s  .c  om*/
            "Tests seed lists are filtered correctly when " + "using the 'Show/Hide unused seed list' filter.");
    addStep("Create a new domain", "The edit domain page should be loaded with only the default "
            + "seed list show. The seed list filter state should be that "
            + "unused seed lists are hidden, eg. the filter link " + "text should 'Show unused seed lists.");
    String domain1ID = createDomainID();
    DomainWebTestHelper.createDomain(new String[] { domain1ID });
    List<WebElement> seedListRows = readSeedListTableRows(driver);
    NASAssert.assertEquals(1, seedListRows.size(), "More than one seed list listed in the new domain");
    NASAssert.assertTrue(seedListRows.get(0).getText().contains("defaultseeds"),
            "Didn't find the defaultseeds as the only seed list");

    addStep("Create a new seed list",
            "The seed list should not be listed initially as the seed list is hidden by the unused filter");
    String seedList1ID = createSeedListID();
    DomainWebTestHelper.createSeedList(domain1ID, seedList1ID, new String[] { domain1ID });
    NASAssert.assertEquals(1, seedListRows.size(), "More than one seed list listed after second "
            + "seed list was created. Should have been hidden by unused filter");

    addStep("Click the 'Show unused seed list' link",
            "The new seed list should appear in the seed list list as the second element.");
    PageHelper.clickLink(SHOW_UNUSED_SEED_LISTS_LINK);
    seedListRows = readSeedListTableRows(driver);
    NASAssert.assertEquals(2, seedListRows.size(), "The second seed list didn't appear in the list after "
            + "clicking the 'Show unused seed lists' link.");
    NASAssert.assertTrue(seedListRows.get(1).getText().contains(seedList1ID),
            "Didn't find the new seed list in the full seed list list.");

    addStep("Click the 'Hide unused seed lists' link",
            "The new seed list should disappear from the seed list list.");
    PageHelper.clickLink(HIDE_UNUSED_SEED_LISTS_LINK);
    seedListRows = readSeedListTableRows(driver);
    NASAssert.assertEquals(1, seedListRows.size(), "More than one seed list listed after second "
            + "seed list was created. Should have been hidden by unused filter");
    NASAssert.assertTrue(seedListRows.get(0).getText().contains("defaultseeds"),
            "Didn't find the defaultconfig as the only seed list");

    addStep("Add the new seed list to the default config (which is a used config)",
            "The seed list should now be listed");
    List<WebElement> configurationRows = readConfigurationTableRows(driver);
    configurationRows.get(0).findElement(By.linkText("Edit")).click();
    Select seedListSelect = new Select(driver.findElement(By.name("seedListList")));
    seedListSelect.selectByVisibleText(seedList1ID);
    driver.findElement(By.cssSelector("input[type=\"submit\"]")).click();
    seedListRows = readSeedListTableRows(driver);
    NASAssert.assertEquals(2, seedListRows.size(),
            "The second seed list didn't appear in the list after " + "it was added to the defaultconfig.");

    addStep("Remove the default seed list from the default configuration",
            "Only the new seed list should now be listed");
    configurationRows = readConfigurationTableRows(driver);
    configurationRows.get(0).findElement(By.linkText("Edit")).click();
    seedListSelect = new Select(driver.findElement(By.name("seedListList")));
    seedListSelect.deselectByVisibleText("defaultseeds");
    driver.findElement(By.cssSelector("input[type=\"submit\"]")).click();
    seedListRows = readSeedListTableRows(driver);
    NASAssert.assertEquals(1, seedListRows.size(), "The default seed list still showing  in the list after "
            + "it was removed from the defaultconfig.");
    NASAssert.assertFalse(seedListRows.get(0).getText().contains("defaultseeds"),
            "Found the defaultseeds in the used seed list list after "
                    + "it was removed from the defaultconfig.");
}

From source file:dk.netarkivet.systemtest.functional.ExtendedFieldTest.java

License:Open Source License

public void extendedDomainStringFieldTest(WebDriver driver, String extendedIDForTest) throws Exception {
    addStep("Create a new String type field (name:" + extendedIDForTest + ") for domains", "");
    PageHelper.gotoPage(PageHelper.MenuPages.ExtendedFields);
    driver.findElement(By.linkText("create Extended Field")).click(); // Todo needs more specific find

    driver.findElement(By.name("extf_name")).clear();
    driver.findElement(By.name("extf_name")).sendKeys(extendedIDForTest);

    Select select = new Select(driver.findElement(By.name("extf_datatype")));
    select.selectByVisibleText("String");

    driver.findElement(By.cssSelector("input[type=\"submit\"]")).click();

    addStep("Edit the default domain (" + HarvestUtils.DEFAULT_DOMAIN + ")",
            "The new extended field should be shown");
    DomainWebTestHelper.editDomain(HarvestUtils.DEFAULT_DOMAIN);
    NASAssert.assertTrue(driver.getPageSource().contains(extendedIDForTest));

    addStep("Fill out the new extended field with a value and save the " + "updated domain", "");

    addStep("Reopen the domain", "The new extended field should contain the newly defined value");
}

From source file:dk.netarkivet.systemtest.functional.HarvestHistoryForDomainPageTest.java

License:Open Source License

@Test(priority = 10, groups = { "guitest", "functest", "slow" })
public void historyTablePagingTest() throws Exception {
    addDescription("Testes that the paging functionality works correctly " + "for the harvest history");
    addStep("Ensure that at least harvests have finished for the default domain", "");
    HarvestUtils.ensureNumberOfHarvestsForDefaultDomain(3);
    List<HarvestHistoryPageHelper.HarvestHistoryEntry> harvestHistory = HarvestHistoryPageHelper
            .readHarvestHistory();/*from ww w .  j a  v  a 2s. com*/
    int PAGE_SIZE = 2;
    setHarvestStatusPageSize(PAGE_SIZE);

    addStep("Set the page size to " + PAGE_SIZE, "");

    addStep("Goto the harvest history for the default domain",
            "Only 2 harvests should be listed and the next link should be enabled.");
    HarvestUtils.gotoHarvestHistoryForDomain(HarvestUtils.DEFAULT_DOMAIN);
    assertEquals("Didn't find the expected 2 harvests on the first page",
            PageHelper.getWebDriver()
                    .findElements(By.xpath("//table[@class='selection_table']/tbody/tr[position()>1]")).size(),
            2);

    addStep("Click the next link until the next link disappears",
            "All the pages should have been listed, 2 at a time");
    int harvestCounter = 0;
    int numberOfPages = (int) Math.ceil((float) harvestHistory.size() / PAGE_SIZE);
    for (int pageNumber = 1; pageNumber <= numberOfPages; pageNumber++) {
        List<WebElement> rows = PageHelper.getWebDriver().findElement(By.className("selection_table"))
                .findElements(By.tagName("tr"));
        rows.remove(0); // Skip headers
        for (int rowNumber = 0; rowNumber < rows.size(); rowNumber++) {
            WebElement row = rows.get(rowNumber);
            assertEquals(new HarvestHistoryPageHelper.HarvestHistoryEntry(row),
                    harvestHistory.get(harvestCounter++));
        }
        boolean lastPage = pageNumber == numberOfPages;
        if (!lastPage) {
            driver.findElement(By.linkText("next")).click();
            PageHelper.waitForPageToLoad();
        } else {
            assertEquals("Not all harvests were found in the pages.", harvestCounter, harvestHistory.size());
            assertTrue(driver.findElements(By.linkText("next")).isEmpty());
        }
    }

    addStep("Click the previous link until the previous link disappears.",
            "All the pages should have been listed, " + "2 at a time backwards.");
    for (int pageNumber = numberOfPages; pageNumber >= 1; pageNumber--) {
        List<WebElement> rows = PageHelper.getWebDriver().findElement(By.className("selection_table"))
                .findElements(By.tagName("tr"));
        rows.remove(0); // Skip headers
        for (int rowNumber = rows.size() - 1; rowNumber >= 0; rowNumber--) {
            WebElement row = rows.get(rowNumber);
            assertEquals(new HarvestHistoryPageHelper.HarvestHistoryEntry(row),
                    harvestHistory.get(--harvestCounter));
        }
        boolean firstPage = pageNumber == 1;
        if (!firstPage) {
            driver.findElement(By.linkText("previous")).click();
            PageHelper.waitForPageToLoad();
        } else {
            assertEquals("Not all harvests where found in the pages.", harvestCounter, 0);
            assertTrue(driver.findElements(By.linkText("previous")).isEmpty());
        }
    }
}