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.java.AppTestType_18_11_2015.java

public void APPROVEUSER(WebDriver driver, String fieldText, String value) {
    //To Handle Approve User Popup 
    //FieldText---The User's FullName   and Value-----OK or Cancel
    try {//w  ww  .j  a v  a2s  . c  om
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.findElement(By.linkText(fieldText)).click();
        Thread.sleep(2000);
        String parentwindow = driver.getWindowHandle();
        if (value.equalsIgnoreCase("OK")) {
            driver.findElement(By.linkText("Approve User")).click();
            Thread.sleep(2000);

            driver.switchTo().alert().accept();

            for (String win : driver.getWindowHandles()) {
                driver.switchTo().window(win);
                try {
                    driver.switchTo().alert().accept();
                } catch (NoAlertPresentException e) {
                    Robot robot = new Robot();
                    robot.keyPress(KeyEvent.VK_SPACE);
                    Thread.sleep(3000);
                }

            }
            Thread.sleep(20000);
            driver.switchTo().window(parentwindow);
            WebDriverWait wait = new WebDriverWait(driver, 20);
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("id_frm_Email_Address")));
            String Email = driver.findElement(By.id("id_frm_Email_Address")).getText();
            driver.findElement(By.name("email")).sendKeys(EMAIL);
            driver.findElement(By.xpath("//input[@value='Search']")).click();

            String Type = driver.findElement(By.xpath("//input[@value='Search']/following::tr[3]/td[6]"))
                    .getText();
            String Active_Status = driver
                    .findElement(By.xpath("//input[@value='Search']/following::tr[3]/td[6]")).getText();
            String BStatus = driver.findElement(By.xpath("//input[@value='Search']/following::tr[3]/td[6]"))
                    .getText();
            String SStatus = driver.findElement(By.xpath("//input[@value='Search']/following::tr[3]/td[6]"))
                    .getText();

            if (Type.equalsIgnoreCase("L") && Active_Status.equalsIgnoreCase("Active")
                    && BStatus.equalsIgnoreCase("Approved") && SStatus.equalsIgnoreCase("Approved")) {
                resultDetails.setFlag(true);
            }
        } else if (value.equalsIgnoreCase("CANCEL")) {
            driver.findElement(By.linkText("Approve User")).click();
            Thread.sleep(2000);
            //Robot robot = new Robot();
            // Simulate SPACE KEY press to click on OK button
            //robot.keyPress(KeyEvent.VK_ESCAPE);
            driver.switchTo().alert().dismiss();
            resultDetails.setFlag(true);

        }

    }

    catch (Exception e) {

        e.printStackTrace();
        resultDetails.setFlag(false);
    }
}

From source file:com.java.AppTestType_18_11_2015.java

public void BIDONOWNLOT(WebDriver driver, String fieldText, String value) {
    try {/*from   w w  w.j  a  v  a2 s.c o  m*/
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        AMPLOGIN(driver, value);
        driver.findElement(By.linkText("Lots")).click();
        Thread.sleep(4000);
        new Select(driver.findElement(By.xpath("//select[@name='venueID']")))
                .selectByVisibleText("EquipmentOne");
        new Select(driver.findElement(By.xpath("//select[@name='offerSrhListingStatus']")))
                .selectByVisibleText("Approved");
        driver.findElement(By.xpath("//input[@name='find_button']")).click();
        driver.findElement(By.xpath("//*[@id='renderView']/table[2]/tbody/tr[1]/td[2]/table/tbody/tr[1]/td/a"))
                .click();
        String EQID = driver
                .findElement(By.xpath("//td[@class='listdatabold' and text()='Lot Number:']/../td[4]"))
                .getText();
        System.out.println("EQID is: " + EQID);
        driver.findElement(By.xpath("//td[@class='listdatabold' and text()='Seller:']/../td[2]/a")).click();
        Thread.sleep(5000);
        String SellerMailID = driver.findElement(By.id("id_frm_Email_Address")).getAttribute("value");
        System.out.println("SellerMailID is: " + SellerMailID);
        AMPLOGOUT(driver);
        driver.get(fieldText);
        WebDriverWait wait = new WebDriverWait(driver, 30);

        driver.findElement(By.name("josso_username")).clear();
        driver.findElement(By.name("josso_username")).sendKeys(SellerMailID);
        driver.findElement(By.name("josso_password")).clear();
        driver.findElement(By.name("josso_password")).sendKeys("Equipment1$");
        driver.findElement(By.xpath("//*[@value='SIGN IN']")).click();
        Thread.sleep(4000);
        driver.findElement(By.id("search")).sendKeys(EQID);
        driver.findElement(By.xpath("//*[@id='main_search']/button")).click();
        Thread.sleep(4000);
        //driver.findElement(By.xpath("(//*[@name='makeoffer'])[2]")).click();

        driver.findElement(By.xpath("(//*[@name='makeoffer'])[2]")).sendKeys("99999999999");
        driver.findElement(By.xpath("(//*[contains(@value,'PLACE A BID')])[2]")).click();
        Thread.sleep(4000);
        driver.findElement(By.xpath("(//input[@class='form-control jsOfferInput e1ConfirmInput'])[2]"))
                .sendKeys("99999999999");
        driver.findElement(By.xpath("(//input[@class='btn btn-primary jsConfirmOffer'])[2]")).click();
        Thread.sleep(4000);
        if (driver.findElement(By.tagName("html")).getText()
                .contains("You are attempting to place a bid on a lot you own, this is not allowed."))
            resultDetails.setFlag(true);

    } catch (Exception e2) {

        e2.printStackTrace();
        resultDetails.setErrorMessage("something went wrong");
        resultDetails.setFlag(false);
    }
}

From source file:com.java.AppTestType_18_11_2015.java

public String FINDLOTID(WebDriver driver, String value) throws Exception {
    String EQID = null;/*from  w ww  . ja v  a 2s.c o m*/
    // try{
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    AMPLOGIN(driver, value);
    driver.findElement(By.linkText("Lots")).click();
    Thread.sleep(4000);
    new Select(driver.findElement(By.xpath("//select[@name='venueID']"))).selectByVisibleText("EquipmentOne");
    new Select(driver.findElement(By.xpath("//select[@name='offerSrhListingStatus']")))
            .selectByVisibleText("Approved");
    driver.findElement(By.xpath("//input[@name='find_button']")).click();
    driver.findElement(By.xpath("//*[@id='renderView']/table[2]/tbody/tr[1]/td[2]/table/tbody/tr[1]/td/a"))
            .click();
    EQID = driver.findElement(By.xpath("//td[@class='listdatabold' and text()='Lot Number:']/../td[4]"))
            .getText();
    System.out.println("EQID is: " + EQID);
    driver.findElement(By.xpath("//*[@name='search_string']")).sendKeys(EQID);
    driver.findElement(By.xpath("//button[text()='Search']")).click();

    /*}
     catch(Exception e)
     {
        e.printStackTrace();
     }*/
    return EQID;

}

From source file:com.java.AppTestType_18_11_2015.java

public void SEARCHLOTINAMP(WebDriver driver, String fieldText, String value) {
    String EQID = null;/*from   w  w w  . j  ava 2 s  . co m*/
    try {
        String AMPUrl = fieldText;
        String AMPPage = value.toUpperCase();
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

        switch (AMPPage) {

        case "LOTS2":

            EQID = FINDLOTID(driver, AMPUrl);
            Thread.sleep(4000);
            driver.findElement(By.linkText("Lots")).click();
            Thread.sleep(2000);
            driver.findElement(By.xpath("//*[text()='Lot Number:']/../td[2]/input")).sendKeys(EQID);
            driver.findElement(By.xpath("//input[@name='find_button']")).click();
            if (driver
                    .findElement(
                            By.xpath("//*[@id='renderView']/table[2]/tbody/tr[1]/td[2]/table/tbody/tr[1]/td/a"))
                    .getText().contains(EQID))
                resultDetails.setFlag(true);
            break;

        case "HOME":
        case "LOTS":

            EQID = FINDLOTID(driver, AMPUrl);
            Thread.sleep(4000);
            driver.findElement(By.linkText(value)).click();
            Thread.sleep(2000);
            driver.findElement(By.xpath("//*[@name='search_string']")).sendKeys(EQID);
            driver.findElement(By.xpath("//button[text()='Search']")).click();
            if (driver.findElement(By.xpath("//td[@class='listdatabold' and text()='Lot Number:']/../td[4]"))
                    .getText().equalsIgnoreCase(EQID))
                resultDetails.setFlag(true);
            break;

        case "VENUE":

            AMPLOGIN(driver, AMPUrl);
            driver.findElement(By.linkText("Lots")).click();
            Thread.sleep(4000);
            new Select(driver.findElement(By.xpath("//select[@name='venueID']")))
                    .selectByVisibleText("EquipmentOne");
            driver.findElement(By.xpath("//input[@name='find_button']")).click();
            int size = driver.findElements(By.xpath("//a[contains(@href,'/o_details.cfm?id=')]")).size();
            for (int i = 1; i <= size; i++) {

                if (driver.findElement(By.xpath("//a[contains(@href,'/o_details.cfm?id=')]")).getText()
                        .contains("(EQ"))
                    resultDetails.setFlag(true);

                else {
                    resultDetails.setFlag(false);
                    break;
                }
            }
            break;

        case "STATUS":

            AMPLOGIN(driver, AMPUrl);
            driver.findElement(By.linkText("Lots")).click();
            Thread.sleep(4000);
            new Select(driver.findElement(By.xpath("//select[@name='venueID']")))
                    .selectByVisibleText("EquipmentOne");
            new Select(driver.findElement(By.xpath("//select[@name='offerSrhListingStatus']")))
                    .selectByVisibleText("Approved");

            driver.findElement(By.xpath("//input[@name='find_button']")).click();
            size = driver.findElements(By.xpath("//a[contains(@href,'/o_details.cfm?id=')]")).size();
            for (int i = 1; i < size * 2; i++) {

                if (driver.findElement(By
                        .xpath("//*[@id='renderView']/table[2]/tbody/tr[" + i + "]/td[1]/table/tbody/tr[3]/td"))
                        .getText().equalsIgnoreCase("Approved")) {
                    resultDetails.setFlag(true);
                    i++;//because, there is one more empry row in table after each and every lot row. So we are skipping that empty row
                }

                else {
                    resultDetails.setFlag(false);
                    break;
                }
            }
            break;

        case "WITHOUTBUYITNOW":

            AMPLOGIN(driver, AMPUrl);
            driver.findElement(By.linkText("Lots")).click();
            Thread.sleep(4000);
            new Select(driver.findElement(By.xpath("//select[@name='venueID']")))
                    .selectByVisibleText("EquipmentOne");
            new Select(driver.findElement(By.xpath("//select[@name='offerSrhListingStatus']")))
                    .selectByVisibleText("Approved");
            System.out.println("is buy it now selected currently: "
                    + driver.findElement(By.xpath("(//*[@name='offerSrhBuyItNowAllowed'])[2]")).isSelected());
            if (driver.findElement(By.xpath("(//*[@name='offerSrhBuyItNowAllowed'])[2]")).isSelected())
                driver.findElement(By.xpath("(//*[@name='offerSrhBuyItNowAllowed'])[2]")).click();

            driver.findElement(By.xpath("//input[@name='find_button']")).click();
            size = driver.findElements(By.xpath("//a[contains(@href,'/o_details.cfm?id=')]")).size();
            driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
            for (int i = 1; i < size * 2; i++) {

                if (driver.findElements(By.xpath("//*[@id='renderView']/table[2]/tbody/tr[" + i
                        + "]/td[1]/table/tbody/tr[2]/td/img[contains(@src,'buyitnow')]")).size() == 0) {
                    resultDetails.setFlag(true);
                    i++; //because, there is one more empry row in table after each and every lot row. So we are skipping that empty row
                }

                else {
                    System.out.println("Lot displayed with BIN");
                    resultDetails.setFlag(false);
                    break;
                }
            }
            driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
            break;

        case "WITHBUYITNOW":

            AMPLOGIN(driver, AMPUrl);
            driver.findElement(By.linkText("Lots")).click();
            Thread.sleep(4000);
            new Select(driver.findElement(By.xpath("//select[@name='venueID']")))
                    .selectByVisibleText("EquipmentOne");
            new Select(driver.findElement(By.xpath("//select[@name='offerSrhListingStatus']")))
                    .selectByVisibleText("Approved");
            if (driver.findElement(By.xpath("//*[@name='offerSrhBuyItNowAllowed']")).isSelected())
                driver.findElement(By.xpath("//*[@name='offerSrhBuyItNowAllowed']")).click();

            driver.findElement(By.xpath("//input[@name='find_button']")).click();
            size = driver.findElements(By.xpath("//a[contains(@href,'/o_details.cfm?id=')]")).size();
            for (int i = 1; i < size * 2; i++) {

                if (driver.findElements(By.xpath("//*[@id='renderView']/table[2]/tbody/tr[" + i
                        + "]/td[1]/table/tbody/tr[2]/td/img[contains(@src,'buyitnow')]")).size() == 1) {
                    resultDetails.setFlag(true);
                    i++; //because, there is one more empry row in table after each and every lot row. So we are skipping that empty row
                }

                else {
                    System.out.println("Lot displayed without BIN");
                    resultDetails.setFlag(false);
                    break;
                }
            }
            break;

        }
    } catch (Exception e) {
        System.out.println(e);
        resultDetails.setFlag(false);
    }

}

From source file:com.java.AppTestType_18_11_2015.java

public void AssetNation(WebDriver driver) {
    try {/*from w w w .  ja v a  2s . com*/
        // Actions to be performed on failure

        if (driver.getPageSource().contains("500 Internal server error")) {
            driver.navigate().refresh();
        }
        int userid = driver.findElements(By.id("iduser")).size();
        int logoutlink = driver.findElements(By.linkText("Logout")).size();
        if (userid > 0) {
            SIGNOUT(driver);
            System.out.println("Clicked on Signout after Fail");
        } else if (logoutlink > 0) {
            AMPLOGOUT(driver);
        }

    } catch (Exception e) {
        System.out.println(e);
    }
}

From source file:com.java.AppTestType_18_11_2015.java

public void VERIFYTHIS_2(WebDriver driver, String fieldText, String value) throws Exception {
    //Used to verify the text in any specific Loctor or Message
    //<XPH or LNK or IDI or TXT><Locator> or MSG in fieldText 
    //Text or Message to be verified in Value
    int i = 0;/*from   w ww .j a  va  2 s  . c o  m*/
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.MILLISECONDS);
    String f = fieldText;
    String val = value;
    String locatorType = f.substring(0, 3);
    String locatorValue = f.substring(3, f.length());
    if (locatorType.equalsIgnoreCase("XPH")) {
        //System.out.println(driver.findElement(By.xpath(locatorValue)).getText());  
        if (driver.findElement(By.xpath(locatorValue)).getText().equalsIgnoreCase(val))
            i = 1;
    } else if (locatorType.equalsIgnoreCase("LNK")) {

        if (driver.findElement(By.linkText(locatorValue)).getText().equalsIgnoreCase(val))
            i = 1;

    }
    if (i == 0) {
        //resultDetails.setErrorMessage(fieldText+" Text is not matching with that of the locator (or) the locator not found");
        resultDetails.setErrorMessage(driver.findElement(By.xpath(locatorValue)).getText() + locatorValue);
        throw new Exception();
    }

}

From source file:com.java.AppTestType_18_11_2015.java

public void WAITFORTHIS_2(WebDriver driver, String fieldText, String value) throws Exception {

    int i = 0;//w w  w . j  av  a2  s  .co m
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.MILLISECONDS);
    String f = fieldText;
    String val = value;
    String locatorType = f.substring(0, 3);
    String locatorValue = f.substring(3, f.length());
    if (locatorType.equalsIgnoreCase("XPH")) {

        if (driver.findElements(By.xpath(locatorValue)).size() > 0)
            i = 1;
    } else if (locatorType.equalsIgnoreCase("LNK")) {

        if (driver.findElements(By.linkText(locatorValue)).size() > 0)
            i = 1;
    }
    if (i == 0) {
        resultDetails.setErrorMessage(fieldText + "Locator Not Found");
        throw new Exception();
    }

}

From source file:com.joyce.automation.util.prop.Prop.java

License:Apache License

/**
 * /*from  ww  w  .java 2  s  . com*/
 * ??:????
 * 
 * @param elementNameInProp
 *            ?key(eg:login.username=id>value )
 * @author jiaozhongbin
 * @throws Exception
 */
public By getLocator(String elementNameInProp) {
    String locator = properties.getProperty(elementNameInProp);
    String locatorType = locator.split(Const.DEFAULT_SPLIT)[0];
    String locatorValue = locator.split(Const.DEFAULT_SPLIT)[1];
    try {
        //         locatorValue = new String(locatorValue.getBytes("ISO-8859-1"), "UTF-8");
        if (locatorType.toLowerCase().equals("id")) {
            return By.id(locatorValue);
        } else if (locatorType.toLowerCase().equals("xpath")) {
            return By.xpath(locatorValue);
        } else if (locatorType.toLowerCase().equals("name")) {
            return By.name(locatorValue);
        } else if (locatorType.toLowerCase().equals("classname") || locatorType.toLowerCase().equals("class")) {
            return By.className(locatorValue);
        } else if (locatorType.toLowerCase().equals("tagname") || locatorType.toLowerCase().equals("tag")) {
            return By.tagName(locatorValue);
        } else if (locatorType.toLowerCase().equals("linktext") || locatorType.toLowerCase().equals("link")) {
            return By.linkText(locatorValue);
        } else if (locatorType.toLowerCase().equals("partiallinktext")) {
            return By.partialLinkText(locatorValue);
        } else if (locatorType.toLowerCase().equals("cssselector") || locatorType.toLowerCase().equals("css")) {
            return By.cssSelector(locatorValue);
        } else
            log.error("locatorType?:" + locatorType);
        return null;
    } catch (IllegalArgumentException e1) {
        log.error("{" + locatorType + "=" + locatorValue + "}?", e1);
    }
    return null;
}

From source file:com.jpablo.test.NavigateWikipedia.java

public void openWikiEnglishFirefox() throws InterruptedException {
    /*//w  ww .  j a v  a  2s .c o  m
    1. Launch Firefox
    2. Open Wikipedia main page
    3. Open Wikipedia in English
    4. Close Firefox
    */

    driver = new FirefoxDriver();

    driver.get("http://www.wikipedia.org");
    link = driver.findElement(By.linkText("English"));
    link.click();

    Thread.sleep(10000);

    driver.quit();
}

From source file:com.jpablo.test.NavigateWikipedia.java

public void doSearchWikiENFF(String sendKeys) throws InterruptedException {
    /*/*from w  w  w .j a va  2  s  .com*/
    1. Launch Firefox
    2. Open Wikipedia main page
    3. Open Wikipedia in English
    4. Type a word to search
    5. Click on Search button
    6. Close Firefox
    */

    driver = new FirefoxDriver();

    driver.get("http://www.wikipedia.org");
    link = driver.findElement(By.linkText("English"));
    link.click();

    Thread.sleep(10000);

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

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