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:com.lemon.web.functional.gui.RegisterFT.java

License:Apache License

@Test
public void register() {
    // /*from  w  ww  .jav a  2 s. c  om*/
    s.open("/logout");
    s.click(By.linkText(""));

    s.type(By.id("loginName"), "user2");
    s.type(By.id("name"), "Kevin");
    s.type(By.id("plainPassword"), "user2");
    s.type(By.id("confirmPassword"), "user2");

    s.click(By.id("submit_btn"));

    // 
    s.waitForTitleContains("");
    assertThat(s.getValue(By.name("username"))).isEqualTo("user2");

    s.type(By.name("password"), "user2");
    s.click(By.id("submit_btn"));

    // ?
    s.waitForTitleContains("?");

    // 
    s.open("/logout");
}

From source file:com.liferay.blade.samples.configuration.action.test.BladeConfigurationActionTest.java

License:Apache License

@Test
public void testBladeConfigurationAction() throws InterruptedException, PortalException {

    _webDriver.get(_portletURL.toExternalForm());

    String url = _webDriver.getCurrentUrl();

    Assert.assertTrue("Portlet was not deployed",
            BladeSampleFunctionalActionUtil.isVisible(_webDriver, _bladeMessagePortlet));

    _bodyWebElement.click();/*from  ww  w  . j  av a 2s.c o m*/

    BladeSampleFunctionalActionUtil.customClick(_webDriver, _verticalEllipsis);

    WebElement configuration = _webDriver.findElement(By.linkText("Configuration"));

    String configurationLink = configuration.getAttribute("href");

    _newWebDriverWindow.get(configurationLink);

    BladeSampleFunctionalActionUtil.customClick(_newWebDriverWindow, _saveButton);

    Assert.assertTrue("Success Message is not visible",
            BladeSampleFunctionalActionUtil.isVisible(_webDriver, _successMessage));

    _webDriver.get(url);

    Assert.assertTrue("Expected Blade Message Portlet, but saw: " + _portletTitle.getText(),
            _portletTitle.getText().contentEquals("Blade Message Portlet"));

    Assert.assertTrue("Expected Hello from BLADE JSP!, but saw: " + _portletBody.getText(),
            _portletBody.getText().contentEquals("Hello from BLADE JSP!"));
}

From source file:com.liferay.cucumber.selenium.WebDriverHelper.java

License:Open Source License

public static By getBy(String locator) {
    if (locator.startsWith("//")) {
        return By.xpath(locator);
    } else if (locator.startsWith("class=")) {
        locator = locator.substring(6);//from  w w  w.j a  v a 2 s .c o m

        return By.className(locator);
    } else if (locator.startsWith("css=")) {
        locator = locator.substring(4);

        return By.cssSelector(locator);
    } else if (locator.startsWith("link=")) {
        locator = locator.substring(5);

        return By.linkText(locator);
    } else if (locator.startsWith("name=")) {
        locator = locator.substring(5);

        return By.name(locator);
    } else if (locator.startsWith("tag=")) {
        locator = locator.substring(4);

        return By.tagName(locator);
    } else if (locator.startsWith("xpath=") || locator.startsWith("xPath=")) {
        locator = locator.substring(6);

        return By.xpath(locator);
    } else {
        return By.id(locator);
    }
}

From source file:com.linagora.obm.ui.page.DeleteUserPage.java

License:Open Source License

public void deleteUserByLogin(String userLogin) {
    driver.findElement(By.linkText(userLogin.toLowerCase())).click();
    driver.findElement(By.id("check_delete_user")).click();
    driver.findElement(By.id("delete_user")).click();
    driver.switchTo().alert().accept();/*from  www  .jav a  2 s . c  om*/

}

From source file:com.mediamelon.UserActions.java

void addAccount(WebDriver driver, List<String> formData) {
    //Verify if the user is logged in as Super User to create a new account. 
    //If not, display message and return

    //Verify if the user is logged in
    String pageTitle = driver.getTitle();
    Assert.assertEquals(pageTitle, "MediaMelon - Home");
    String fullName = driver.findElement(By.xpath("//div[@class='row data']/div/div[1]/p[2]")).getText();
    String role = driver.findElement(By.xpath("//div[@class='row data']/div/div[3]/p[2]")).getText();

    if (fullName.equalsIgnoreCase("Super User") && role.equalsIgnoreCase("admin")) {

        System.out.println("List of Accounts is displayed");
        //expand the settings menu option and click on Account Management
        List<WebElement> dropDownOptions = driver.findElements(By.className("dropdown-toggle"));
        dropDownOptions.get(0).click();/*from  ww w  .  j av a  2  s  . c  o m*/
        WebElement accountManagement = driver.findElement(By.cssSelector(".dropdown-menu.dropdown-admin"));
        Assert.assertTrue(accountManagement.isDisplayed());
        accountManagement.findElement(By.linkText("Account Management")).click();

        Assert.assertEquals(driver.getTitle(), "List of Accounts");

        WebElement accountsTable = driver.findElement(By.xpath("//div[@class='row well']/table"));
        Assert.assertTrue(accountsTable.isDisplayed());
        WebElement addAccountBtn = driver.findElement(By.cssSelector(".btn.btn-primary"));

        System.out.println("Clicking on Add a new account button");
        Assert.assertEquals(addAccountBtn.getText(), "Add a new Account");
        addAccountBtn.click();

        //Fill account add form
        WebElement accountForm = driver.findElement(By.tagName("form"));
        Assert.assertTrue(accountForm.isDisplayed());
        System.out.println(accountForm.getAttribute("action"));

        accountForm.findElement(By.id("companyName")).sendKeys(formData.get(0));
        accountForm.findElement(By.id("companyWebsite")).sendKeys(formData.get(1));
        accountForm.findElement(By.id("adminName")).sendKeys(formData.get(2));
        accountForm.findElement(By.id("adminEmail")).sendKeys(formData.get(3));

        Select licenseType = new Select(driver.findElement(By.id("licenseType")));
        licenseType.selectByVisibleText(formData.get(4));

        Select services = new Select(driver.findElement(By.id("services")));
        String requiredServices = formData.get(5);
        String multipleSel[] = formData.get(5).split(",");

        if (requiredServices.equalsIgnoreCase("All")) {
            services.selectByIndex(0);
            services.selectByIndex(1);
            services.selectByIndex(2);
        } else if (multipleSel.length > 1) {
            for (int i = 0; i < multipleSel.length; i++)
                services.selectByVisibleText(multipleSel[i]);
        } else
            services.selectByVisibleText(requiredServices);

        accountForm.findElement(By.id("companyName")).sendKeys(formData.get(5));
        //submit the form
        System.out.println("Submitting the form");
        accountForm.findElement(By.cssSelector("button[value='submit']")).click();
        System.out.println("clicked on submit button");

        accountsTable = driver.findElement(By.cssSelector("table.table-striped.table-hover.table-bordered"));
        Assert.assertTrue(accountsTable.isDisplayed());
        System.out.println("form submitted sucessfully");

        //Verify the presence of newly created account in the list of accounts
        System.out.println("Verifying if the newly created account is present in the list");
        String tableData = accountsTable.getText();
        System.out.println("Table Data: " + tableData);
        //findElement(By.xpath(".//*[@class='studyResultsId']/div/table/tbody/tr/td")).getText();

        //Retrieving the data from the Td of table in to a string
        if (tableData.contains(formData.get(5))) {
            System.out.println("contains newly created account");
        } else {
            System.out.println("does not contains newly created account");
        }
    } else
        System.out.println("User not authorized to create an account");

}

From source file:com.mkl.websuites.command.OperationOnWebElement.java

License:Apache License

@Override
protected void runCommandWithParameters() {

    by = null;/*from  w  w w  . j  a  v  a 2  s . co  m*/

    if (parameterMap.keySet().contains("id")) {
        by = By.id(parameterMap.get("id"));
    }

    if (parameterMap.keySet().contains("css")) {
        by = By.cssSelector(parameterMap.get("css"));
    }

    if (parameterMap.keySet().contains("xpath")) {
        by = By.xpath(parameterMap.get("xpath"));
    }

    if (parameterMap.keySet().contains("className")) {
        by = By.className(parameterMap.get("className"));
    }

    if (parameterMap.keySet().contains("linkText")) {
        by = By.linkText(parameterMap.get("linkText"));
    }

    if (parameterMap.keySet().contains("partialLinkText")) {
        by = By.partialLinkText(parameterMap.get("partialLinkText"));
    }

    if (parameterMap.keySet().contains("name")) {
        by = By.name(parameterMap.get("name"));
    }

    if (parameterMap.keySet().contains("tagName")) {
        by = By.tagName(parameterMap.get("tagName"));
    }

    try {

        WebElement elem = browser.findElement(by);

        foundElement = elem;

        doOperationOnElement(elem);

    } catch (NoSuchElementException e) {

        fail("No element found for selecor " + by + " can be found on the page. " + "Selection parameters: "
                + parameterMap);
    }
}

From source file:com.mkl.websuites.command.OperationOnWebElementTest.java

License:Apache License

@Test
public void shouldRunForLinkText(@Mocked final WebDriver browser) {
    runFor(browser, "linkText", "someLinkText", By.linkText("someLinkText"));
}

From source file:com.mkl.websuites.internal.command.impl.check.CheckLinkTextCommand.java

License:Apache License

@Override
protected String getStringParam() {

    try {/*from   w  w w  .ja  v  a 2  s  .com*/
        foundElem = browser.findElement(By.linkText(expectedLinkText));
    } catch (NoSuchElementException e) {
        return null;
    }

    return "OK";
}

From source file:com.moodle.testmanager.pageObjectModel.AssignmentSubmissionComments.java

License:GNU General Public License

/**
 * Clicks the link to save a submission comment.
 *//*from  w ww  . j  av  a  2 s .com*/
public void clickLinkSaveComment() {
    WebElement link = driver.findElement(By.linkText(this.properties.get("linkSaveComment")));
    link.click();
}

From source file:com.moodle.testmanager.pageObjectModel.AssignmentSubmissionComments.java

License:GNU General Public License

/**
 * Clicks the link to cancel a submission comment.
 *//*from  ww  w.  ja  v a  2  s . com*/
public void clickLinkCancelComment() {
    WebElement link = driver.findElement(By.linkText(this.properties.get("linkCancelComment")));
    link.click();
}