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.jpablo.test.TutorialSelenium.java

public void testIE() throws InterruptedException {
    System.setProperty("webdriver.ie.driver", "C:\\IEDriverServer.exe");

    /*DesiredCapabilities caps = DesiredCapabilities.internetExplorer(); 
    caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
        true);//from  ww w .j  av a 2 s.  co  m
            
    driver = new InternetExplorerDriver(caps);
    */
    driver = new InternetExplorerDriver();
    driver.get("http://www.wikipedia.org");
    link = driver.findElement(By.linkText("English"));
    link.click();

    Thread.sleep(5000);

    searchBox = driver.findElement(By.id("searchInput"));
    searchBox.sendKeys("Software");
    searchBox.submit();

    Thread.sleep(5000);
    driver.quit();
}

From source file:com.kazuki43zoo.jpetstore.JpetstoreApplicationTests.java

License:Apache License

@After
public void logout() {
    SelenideElement element = $(By.linkText("Sign Out"));
    if (element.exists()) {
        element.click();
    }
}

From source file:com.kazuki43zoo.jpetstore.JpetstoreApplicationTests.java

License:Apache License

@Test
public void testOrder() {

    // Open the home page
    open("/");/* w  w w .j ava  2  s  .  c om*/
    assertThat(title()).isEqualTo("JPetStore Demo");

    // Move to the top page
    $(By.linkText("Enter the Store")).click();
    $(By.id("WelcomeContent")).shouldBe(text(""));

    // Move to sign in page & sign
    $(By.linkText("Sign In")).click();
    $(By.name("username")).val("j2ee");
    $(By.name("password")).val("j2ee");
    $(By.id("login")).click();
    $(By.id("WelcomeContent")).$(By.tagName("span")).shouldBe(text("ABC"));

    // Search items
    $(By.name("keywords")).val("fish");
    $(By.id("searchProducts")).click();
    $$(By.cssSelector("#Catalog table tr")).shouldHaveSize(3);

    // Select item
    $(By.linkText("Fresh Water fish from China")).click();
    $(By.cssSelector("#Catalog h2")).shouldBe(text("Goldfish"));

    // Add a item to the cart
    $(By.linkText("Add to Cart")).click();
    $(By.cssSelector("#Catalog h2")).shouldBe(text("Shopping Cart"));

    // Checkout cart items
    $(By.linkText("Proceed to Checkout")).click();
    assertThat(title()).isEqualTo("JPetStore Demo");

    // Input card information & Confirm order information
    $(By.name("creditCard")).val("9999999999");
    $(By.name("expiryDate")).val("04/2020");
    $(By.name("continue")).click();
    $(By.id("confirmMessage")).shouldBe(text("Please confirm the information below and then press submit..."));

    // Submit order
    $(By.id("order")).click();
    $(By.cssSelector(".messages li")).shouldBe(text("Thank you, your order has been submitted."));
    String orderId = $(By.id("orderId")).text();

    // Show profile page
    $(By.linkText("My Account")).click();
    $(By.cssSelector("#Catalog h3")).shouldBe(text("User Information"));

    // Show orders
    $(By.linkText("My Orders")).click();
    $(By.cssSelector("#Content h2")).shouldBe(text("My Orders"));

    // Show order detail
    $(By.linkText(orderId)).click();
    assertThat($(By.id("orderId")).text()).isEqualTo(orderId);

    // Sign out
    $(By.linkText("Sign Out")).click();
    $(By.id("WelcomeContent")).shouldBe(text(""));

}

From source file:com.kazuki43zoo.jpetstore.JpetstoreApplicationTests.java

License:Apache License

@Test
public void testUpdateProfile() {
    // Open the home page
    open("/");/*from w  w w.  j  a v a 2  s . c o m*/
    assertThat(title()).isEqualTo("JPetStore Demo");

    // Move to the top page
    $(By.linkText("Enter the Store")).click();
    $(By.id("WelcomeContent")).shouldBe(text(""));

    // Move to sign in page & sign
    $(By.linkText("Sign In")).click();
    $(By.name("username")).val("j2ee");
    $(By.name("password")).val("j2ee");
    $(By.id("login")).click();
    $(By.id("WelcomeContent")).$(By.tagName("span")).shouldBe(text("ABC"));

    // Show profile page
    $(By.linkText("My Account")).click();
    $(By.cssSelector("#Catalog h3")).shouldBe(text("User Information"));
    $$(By.cssSelector("#Catalog table td")).get(1).shouldBe(text("j2ee"));

    // Edit account
    $(By.id("save")).click();
    $(By.cssSelector("#Catalog h3")).shouldBe(text("User Information"));
    $$(By.cssSelector("#Catalog table td")).get(1).shouldBe(text("j2ee"));
}

From source file:com.kazuki43zoo.jpetstore.JpetstoreApplicationTests.java

License:Apache License

@Test
public void testRegistrationUser() {
    // Open the home page
    open("/");//from   w ww. ja v a 2 s  .  co  m
    assertThat(title()).isEqualTo("JPetStore Demo");

    // Move to the top page
    $(By.linkText("Enter the Store")).click();
    $(By.id("WelcomeContent")).shouldBe(text(""));

    // Move to sign in page & sign
    $(By.linkText("Sign In")).click();
    $(By.cssSelector("#Catalog p")).shouldBe(text("Please enter your username and password."));

    // Move to use registration page
    $(By.linkText("Register Now!")).click();
    $(By.cssSelector("#Catalog h3")).shouldBe(text("User Information"));

    // Create a new user
    String userId = String.valueOf(System.currentTimeMillis());
    $(By.name("username")).val(userId);
    $(By.name("password")).val("password");
    $(By.name("repeatedPassword")).val("password");
    $(By.name("firstName")).val("Jon");
    $(By.name("lastName")).val("MyBatis");
    $(By.name("email")).val("jon.mybatis@test.com");
    $(By.name("phone")).val("09012345678");
    $(By.name("address1")).val("Address1");
    $(By.name("address2")).val("Address2");
    $(By.name("city")).val("Minato-Ku");
    $(By.name("state")).val("Tokyo");
    $(By.name("zip")).val("0001234");
    $(By.name("country")).val("Japan");
    $(By.name("languagePreference")).selectOption("Japanese");
    $(By.name("favouriteCategoryId")).selectOption("CATS");
    $(By.name("listOption")).setSelected(true);
    $(By.name("bannerOption")).setSelected(true);
    $(By.id("save")).click();
    $(By.cssSelector(".messages li")).shouldBe(text("Your account has been created. Please try login !!"));

    // Move to sign in page & sign
    $(By.name("username")).val(userId);
    $(By.name("password")).val("password");
    $(By.id("login")).click();
    $(By.id("WelcomeContent")).$(By.tagName("span")).shouldBe(text("Jon"));

}

From source file:com.kazuki43zoo.jpetstore.JpetstoreApplicationTests.java

License:Apache License

@Test
public void testSelectItems() {
    // Open the home page
    open("/");/*from ww  w.j a  va2 s .  co m*/
    assertThat(title()).isEqualTo("JPetStore Demo");

    // Move to the top page
    $(By.linkText("Enter the Store")).click();
    $(By.id("WelcomeContent")).shouldBe(text(""));

    // Move to category
    $(By.cssSelector("#SidebarContent a")).click();
    $(By.cssSelector("#Catalog h2")).shouldBe(text("Fish"));

    // Move to items
    $(By.linkText("FI-SW-01")).click();
    $(By.cssSelector("#Catalog h2")).shouldBe(text("Angelfish"));

    // Move to item detail
    $(By.linkText("EST-1")).click();
    $$(By.cssSelector("#Catalog table tr td")).get(2).shouldBe(text("Large Angelfish"));

    // Back to items
    $(By.linkText("Return to FI-SW-01")).click();
    $(By.cssSelector("#Catalog h2")).shouldBe(text("Angelfish"));

    // Back to category
    $(By.linkText("Return to FISH")).click();
    $(By.cssSelector("#Catalog h2")).shouldBe(text("Fish"));

    // Back to the top page
    $(By.linkText("Return to Main Menu")).click();
    $(By.id("WelcomeContent")).shouldBe(text(""));

}

From source file:com.kazuki43zoo.jpetstore.JpetstoreApplicationTests.java

License:Apache License

@Test
public void testViewCart() {

    // Open the home page
    open("/");/* w  w w.  j a v  a2s .c o  m*/
    assertThat(title()).isEqualTo("JPetStore Demo");

    // Move to the top page
    $(By.linkText("Enter the Store")).click();
    $(By.id("WelcomeContent")).shouldBe(text(""));

    // Move to cart
    $(By.name("img_cart")).click();
    $(By.cssSelector("#Catalog h2")).shouldBe(text("Shopping Cart"));

}

From source file:com.kazuki43zoo.jpetstore.JpetstoreApplicationTests.java

License:Apache License

@Test
public void testViewHelp() {

    // Open the home page
    open("/");// w  w w. ja  v  a 2s  .c  o  m
    assertThat(title()).isEqualTo("JPetStore Demo");

    String mainWindow = getWebDriver().getWindowHandle();

    // Move to the top page
    $(By.linkText("Enter the Store")).click();
    $(By.id("WelcomeContent")).shouldBe(text(""));

    // Move to help
    $(By.linkText("?")).click();

    Set<String> windows = new HashSet<>(getWebDriver().getWindowHandles());
    windows.remove(mainWindow);
    switchTo().window(windows.iterator().next());

    $(By.cssSelector("#Content h1")).shouldBe(text("JPetStore Demo"));

}

From source file:com.lazerycode.ebselen.handlers.locatorhandler.AutoLocatorTest.java

License:Apache License

@Test
public void givenALinkTextLocatorCodeReturnsCorrectType() throws Exception {
    assertThat(loc.autoLocator("link=home"), is(equalTo(By.linkText("home"))));
}

From source file:com.lazerycode.ebselen.handlers.LocatorHandler.java

License:Apache License

/**
 * Take a locator and work out what sort of By.xxx should be used
 *
 * @param locator - locator to evaluate/*w  w  w  .  j a  v  a 2  s. c  o m*/
 * @return By - a By format that sky.sns.selenium 2 can utilise
 */
public By autoLocator(String locator) {
    switch (getLocatorType(locator)) {
    case XPATH:
        if (locator.startsWith("xpath=")) {
            locator = locator.split("=", 2)[1];
        }
        return By.xpath(locator);
    case CSS_SELECTOR:
        if (locator.startsWith("css=")) {
            locator = locator.split("=", 2)[1];
        }
        return By.cssSelector(locator);
    case ID:
        if (locator.startsWith("id=")) {
            locator = locator.split("=", 2)[1];
        }
        return By.id(locator);
    case NAME:
        if (locator.startsWith("name=")) {
            locator = locator.split("=", 2)[1];
        }
        return By.name(locator);
    case CLASS_NAME:
        if (locator.startsWith("class=")) {
            locator = locator.split("=", 2)[1];
        }
        return By.className(locator);
    case TAG_NAME:
        if (locator.startsWith("tag=")) {
            locator = locator.split("=", 2)[1];
        }
        return By.tagName(locator);
    case LINK_TEXT:
        if (locator.startsWith("link=")) {
            locator = locator.split("=", 2)[1];
        }
        return By.linkText(locator);
    default:
        if (locator.startsWith("dom:name=")) {
            locator = locator.split("=", 2)[1];
            return By.xpath("//form[@name='" + locator + "']");
        } else if (locator.startsWith("dom:index=")) {
            locator = locator.split("=", 2)[1];
            return By.xpath("(//form)[" + locator + "]");
        }
    }
    return null;
}