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 APPROVEDLG(WebDriver driver) {

    try {/*from w w  w  .java  2 s .  c o m*/

        String parent = driver.getWindowHandle();

        System.out.println(parent);

        driver.findElement(By.linkText("Approve")).click();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        ;

        driver.switchTo().window("changeSTatus");
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        ;

        driver.findElement(By.name("reason")).sendKeys("approve");

        driver.findElement(By.name("verify")).click();

        driver.findElement(By.xpath("//input[@value='Approve']")).click();

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        ;
        driver.switchTo().window(parent);

        LOTNUMBER = driver.findElement(By.xpath("//td[4]")).getText();
        System.out.println(LOTNUMBER);

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

        driver.manage().deleteAllCookies();
        driver.navigate().refresh();

        resultDetails.setFlag(true);
    }

    catch (Exception e) {

        resultDetails.setFlag(false);
    }
}

From source file:com.java.AppTestType_18_11_2015.java

public void AMPTOOL(WebDriver driver, String fieldText, String value) {

    String fieldType = fieldText.substring(0, 3);
    String field = fieldText.substring(3, fieldText.length());

    try {/*  w ww. j  av  a2  s .c o m*/

        AppKeyWords ampkey = AppKeyWords.valueOf(fieldType.toUpperCase());

        switch (ampkey) {

        case USR:

            try {

                driver.findElement(By.linkText(field)).click();
                driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

                resultDetails.setErrorMessage("Link is clicked");

                /* see if manually entering the email id will accept and enters in the field
                 * try changing hte locators, may be u selected wrong one?
                 * try directly from AMP by creating separate method.
                 */

                //                driver.findElement(By.cssSelector("input[name='email']")).sendKeys(Fname+lname+inc+ID);
                //                
                //                System.out.println(Fname+lname+inc+ID);
                //                
                //                driver.findElement(By.cssSelector("td > input[type='button']")).click();

            }

            catch (Exception e) {

                resultDetails.setFlag(false);
            }

            break;

        }

        Thread.sleep(6000);

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

    } catch (Exception e) {
    }

    resultDetails.setFlag(true);
}

From source file:com.java.AppTestType_18_11_2015.java

public void READCSV(WebDriver driver) {

    driver.get("http://mmtool.staging.assetnation.com"); // Change again back to staging AMP Site.
    driver.manage().deleteAllCookies();//from w w  w. j  a  va2 s. c  o  m
    driver.findElement(By.id("aurid")).sendKeys("mglaz@assetnation.com");

    driver.findElement(By.id("apwd")).sendKeys("Equipment1$");
    driver.findElement(By.xpath("//input[@value='Login']")).click();

    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

    driver.findElement(By.id("userAgreementBtn")).click();

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

    /* reading of Excel file and saving into Array. */

    Scanner s = new Scanner(System.in);

    try {

        File f = new File("E:/JMeter/fullusers.txt");

        Scanner numScan = new Scanner(f);

        String line;

        while (numScan.hasNext()) {
            line = numScan.nextLine();
            System.out.print(line + " ");

            driver.findElement(By.name("email")).sendKeys(line);

            driver.findElement(By.xpath("//input[@value='Search']")).click();

            driver.findElement(By.xpath("//td/a")).click();
            Thread.sleep(10000);

            String ParentHandle = driver.getWindowHandle();
            driver.findElement(By.linkText("Approve User")).click();
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
            ;
            driver.switchTo().alert().accept();
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
            ;
            for (String winHandle : driver.getWindowHandles()) {

                System.out.println("Entered For Loop");
                driver.switchTo().window(winHandle);
            }

            Thread.sleep(10000);
            driver.switchTo().alert().accept();
            Thread.sleep(10000);
            driver.switchTo().window(ParentHandle);

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

            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        }

        resultDetails.setFlag(true);

    } catch (Exception e) {

    }

}

From source file:com.java.AppTestType_18_11_2015.java

public void BROWSEALLEVENTS(WebDriver driver) {

    try {/*ww  w .ja v  a2 s.  com*/
        WebElement element = driver.findElement(By.linkText("ALL EQUIPMENT"));
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("arguments[2].click()", element);

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        ;

        driver.findElement(By.xpath("//div[11]/div[2]/a/span")).click();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        ;

        String EO = driver.findElement(By.cssSelector("span.e1Count")).getText();
        System.out.println(EO);

        String EOCount = EO.substring(EO.indexOf("(") + 1, EO.lastIndexOf(")"));

        System.out.println(EOCount);

        String match = driver.findElement(By.id("e1ResultsFound")).getText();
        System.out.println(match);

        //String matchcount = match.replaceAll("\\D+", ""); //This will extracts only integers from the string.

        //System.out.println(matchcount);

        if (EOCount.equalsIgnoreCase(match)) {

            System.out.println("count matched!!");

            resultDetails.setFlag(true);
        }
    }

    catch (Exception e) {

        resultDetails.setFlag(false);
    }
}

From source file:com.java.AppTestType_18_11_2015.java

public void FACETS(WebDriver driver, String fieldText, String value) {

    String fieldType = fieldText;
    String field = fieldText;//from ww w. j av  a  2 s  .c o m
    try {
        AppKeyWords FCT = AppKeyWords.valueOf(fieldType.toUpperCase());
        ALLEQUIPMENTPAGE(driver);
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        switch (FCT) {

        case MAKE:

            try {

                // suman
                // driver.findElement(By.linkText("ALL EQUIPMENT")).click();
                Thread.sleep(2000);
                driver.findElement(By.linkText("Make")).click();
                Thread.sleep(2000);
                driver.findElement(By.xpath("(//*[@id='Make']/ul/li[1]/span/input)[2]")).click();

                Thread.sleep(1000);

                String Makecount = driver.findElement(By.xpath("(//*[@id='Make']/ul/li[1])[2]")).getText();

                System.out.println(Makecount);

                String RBMakecount = Makecount.substring(Makecount.indexOf("(") + 1,
                        Makecount.lastIndexOf(")"));
                Integer totalCount = Integer.parseInt(RBMakecount);
                System.out.println("Expected count: " + totalCount);
                boolean result = FACETS_COMPARISON(driver, totalCount);

                if (result) {
                    resultDetails.setFlag(true);
                } else
                    System.out.println("count mis-matched");

            } catch (Exception e) {

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

            break;

        case CATEGORY:

            try {

                driver.findElement(By.xpath("//li/input")).click();

                String Categorycount = driver.findElement(By.xpath("//div[10]/div/div/ul/li/a")).getText();
                String RBCategorycount = Categorycount.substring(Categorycount.indexOf("(") + 1,
                        Categorycount.lastIndexOf(")"));
                System.out.println(RBCategorycount);

                String categoryfinal = driver.findElement(By.id("e1NumFound")).getText();
                if (RBCategorycount.equalsIgnoreCase(categoryfinal)) {

                    resultDetails.setFlag(true);
                    System.out.println("Counts matched!!!");
                }

            } catch (Exception e) {

                resultDetails.setFlag(false);
            }

            break;

        case MODEL:

            try {

                driver.findElement(By.linkText("Model")).click();
                Thread.sleep(2000);
                driver.findElement(By.xpath("(//*[@id='Model']/ul/li[1]/span/input)[2]")).click();

                Thread.sleep(1000);

                String Makecount = driver.findElement(By.xpath("(//*[@id='Model']/ul/li[1])[2]")).getText();

                System.out.println(Makecount);

                String RBMakecount = Makecount.substring(Makecount.indexOf("(") + 1,
                        Makecount.lastIndexOf(")"));
                Integer totalCount = Integer.parseInt(RBMakecount);
                System.out.println("Expected count: " + totalCount);
                Thread.sleep(3000);
                boolean result = FACETS_COMPARISON(driver, totalCount);

                if (result) {
                    resultDetails.setFlag(true);
                } else
                    System.out.println("count mis-matched");

            } catch (Exception e) {

                resultDetails.setFlag(false);
            }
            break;

        case COUNTRY:

            try {

                Thread.sleep(2000);
                driver.findElement(By.linkText("Country")).click();
                Thread.sleep(2000);
                driver.findElement(By.xpath("(//*[@id='Country']/ul/li[1]/span/input)[2]")).click();

                Thread.sleep(1000);

                String Makecount = driver.findElement(By.xpath("(//*[@id='Country']/ul/li[1])[2]")).getText();

                System.out.println(Makecount);

                String RBMakecount = Makecount.substring(Makecount.indexOf("(") + 1,
                        Makecount.lastIndexOf(")"));
                Integer totalCount = Integer.parseInt(RBMakecount);
                System.out.println("Expected count: " + totalCount);
                Thread.sleep(3000);
                boolean result = FACETS_COMPARISON(driver, totalCount);

                if (result) {
                    resultDetails.setFlag(true);
                } else
                    System.out.println("count mis-matched");

            } catch (Exception e) {
                System.out.println("entered in catch block " + e);
                resultDetails.setFlag(false);
            }

            break;

        case STATE:
            try {

                driver.findElement(By.linkText("State/Province")).click();
                Thread.sleep(2000);
                driver.findElement(By.xpath("(//*[@id='State/Province']/ul/li[1]/span/input)[2]")).click();

                Thread.sleep(1000);

                String Makecount = driver.findElement(By.xpath("(//*[@id='State/Province']/ul/li[1])[2]"))
                        .getText();

                System.out.println(Makecount);

                String RBMakecount = Makecount.substring(Makecount.indexOf("(") + 1,
                        Makecount.lastIndexOf(")"));
                Integer totalCount = Integer.parseInt(RBMakecount);
                System.out.println("Expected count: " + totalCount);
                Thread.sleep(3000);
                boolean result = FACETS_COMPARISON(driver, totalCount);

                if (result) {
                    resultDetails.setFlag(true);
                } else
                    System.out.println("count mis-matched");

            } catch (Exception e) {

                resultDetails.setErrorMessage("The count don't match!");
                resultDetails.setFlag(false);
            }
            break;

        case SOURCESITE:

            try {
                Thread.sleep(3000);
                String msg = driver.findElement(By.id("e1SitesFound")).getText();
                driver.findElement(By.linkText("Source Site")).click();
                Thread.sleep(2500);

                if (msg.contains("Ritchie Bros"))
                    driver.findElement(By.xpath("(//*[@id='site_id:RBA']/span[1]/input)[2]")).click();
                Thread.sleep(3000);
                if (msg.contains("SalvageSale"))
                    driver.findElement(By.xpath("(//*[@id='site_id:SS']/span[1]/input)[2]")).click();

                Thread.sleep(3000);

                //String E1Count = driver.findElement(By.cssSelector("span.e1Count")).getText();//
                System.out.println("size1 issssssssssssssssssss: "
                        + driver.findElements(By.xpath("(//*[@id='site_id:E1']/span[3])[2]")).size());
                String E1Count = driver.findElement(By.xpath("(//*[@id='site_id:E1']/span[3])[2]")).getText();
                System.out.println(E1Count);
                String EOCountt = E1Count.substring(E1Count.indexOf("(") + 1, E1Count.lastIndexOf(")"));
                Integer count1 = Integer.parseInt(EOCountt);
                System.out.println("count1 is: " + count1);

                Integer totalCount = count1;
                //suman

                Thread.sleep(5000);
                System.out.println(
                        "size2 isssssssssssssssssssssss" + driver.findElements(By.id("e1NumFound")).size());
                System.out.println(
                        "size3 isssssssssssssssssssssss" + driver.findElements(By.id("e1ResultsFound")).size());
                String listingcount = driver.findElement(By.id("e1NumFound")).getText();
                String eventcount = driver.findElement(By.id("e1ResultsFound")).getText();

                System.out.println(listingcount);
                System.out.println(eventcount);
                boolean lotDisplay = driver.findElement(By.id("e1NumFound")).isDisplayed();//To verify lot count if displayed or not
                boolean eventDisplay = driver.findElement(By.id("e1ResultsFound")).isDisplayed();

                String listingcount2 = "";
                int convlistingcount = 0;
                if (lotDisplay) {
                    listingcount2 = listingcount.replace(",", "");
                    convlistingcount = Integer.parseInt(listingcount2);
                }

                String eventcount2 = "";
                int conveventcount = 0;
                if (eventDisplay) {
                    eventcount2 = eventcount.replace(",", "");
                    conveventcount = Integer.parseInt(eventcount2);

                }
                System.out.println("lot count is: " + convlistingcount);
                System.out.println("event count is: " + conveventcount);

                int myfinalcount = convlistingcount + conveventcount;
                String compfinalcount = String.valueOf(myfinalcount);

                System.out.println(totalCount);
                System.out.println(myfinalcount);

                if (myfinalcount == totalCount) {

                    resultDetails.setFlag(true);
                    System.out.println("Counts matched!");
                } else
                    resultDetails.setFlag(false);
            } catch (Exception e) {

                resultDetails.setFlag(false);
            }

            break;

        case POSTALCODE:

            try {
                WebDriverWait wait = new WebDriverWait(driver, 30);
                wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("(//*[@id='Zip']/a)[2]")));

                driver.findElement(By.xpath("(//*[@id='Zip']/a)[2]")).click();
                Thread.sleep(1000);
                driver.findElement(By.xpath("(//button[contains(@class,'zip_search')])[2]")).click();
                Thread.sleep(1000);
                if (driver.findElement(By.xpath("//*[@class='zip_code']/../div/ul/li")).getText()
                        .equalsIgnoreCase("Required Field.")) {

                    resultDetails.setFlag(true);
                }

            } catch (Exception e) {

                resultDetails.setFlag(false);
            }

            break;
        }

    } catch (Exception e) {

        resultDetails.setFlag(false);
    }
}

From source file:com.java.AppTestType_18_11_2015.java

public void SEARCHRESULTS(WebDriver driver, String fieldText, String value) {

    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    String fieldType = fieldText;
    String field = fieldText;/*from  w  ww.  j a  v  a  2 s .co  m*/
    try {
        AppKeyWords SER = AppKeyWords.valueOf(fieldType.toUpperCase());

        switch (SER) {

        case AGRI:

            driver.findElement(By.linkText("AGRICULTURE")).click();
            //suman
            Thread.sleep(3000);
            boolean b = SEARCH_RESULT_COMPARISON(driver);
            System.out.println(b);
            if (b) {

                resultDetails.setFlag(true);
                System.out.println("Counts matched!");
            } else
                resultDetails.setFlag(false);

            break;

        case TRANS:

            driver.findElement(By.xpath("(//a[text()='Transportation'])")).click();

            Thread.sleep(3000);
            boolean b2 = SEARCH_RESULT_COMPARISON(driver);
            System.out.println(b2);
            if (b2) {

                resultDetails.setFlag(true);
                System.out.println("Counts matched!");
            } else
                resultDetails.setFlag(false);

            break;

        case CONS:

            driver.findElement(By.xpath("//a[text()='Construction']")).click();
            Thread.sleep(3000);
            boolean b3 = SEARCH_RESULT_COMPARISON(driver);
            System.out.println(b3);
            if (b3) {

                resultDetails.setFlag(true);
                System.out.println("Counts matched!");
            } else
                resultDetails.setFlag(false);

            break;

        case ENER:

            try {
                driver.findElement(By.xpath("(//a[contains(text(),'Energy')])[4]")).click();
            } catch (Exception e) {
                driver.findElement(By.xpath("http://e1.dev.assetnation.com/energy-equipment")).click();
            }

            Thread.sleep(3000);
            boolean b4 = SEARCH_RESULT_COMPARISON(driver);
            System.out.println(b4);
            if (b4) {

                resultDetails.setFlag(true);
                System.out.println("Counts matched!");
            } else
                resultDetails.setFlag(false);

            break;

        case SEARCH:
            try {
                driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
                driver.findElement(By.id("search")).sendKeys("trucks");
                Thread.sleep(1500);
                //driver.findElement(By.xpath("//[@id='main_search']/button")).click();
                driver.findElement(By.id("search")).sendKeys(Keys.ENTER);
                Thread.sleep(3000);
                boolean b5 = SEARCH_RESULT_COMPARISON(driver);
                System.out.println(b5);
                if (b5) {

                    resultDetails.setFlag(true);
                    System.out.println("Counts matched!");
                } else
                    resultDetails.setFlag(false);
            } catch (Exception e) {
                resultDetails.setFlag(false);
                e.printStackTrace();
            }

            break;

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

From source file:com.java.AppTestType_18_11_2015.java

public String QA(WebDriver driver) throws FileNotFoundException, InterruptedException {

    try {//from  w w w.  ja va 2s .co m

        driver.findElement(By.linkText("ALL EQUIPMENT")).click();

        Thread.sleep(10000);

        List<WebElement> listings = driver.findElements(By.cssSelector("a[href*='/listing?listingid']"));

        Random r = new Random();

        int randomvalue = r.nextInt(listings.size());
        listings.get(randomvalue).click();

        System.out.println(randomvalue);

        getvalue = driver.findElement(By.xpath("//div[7]/span")).getText();
        System.out.println(getvalue);

        driver.findElement(By.xpath("//div[3]/div[2]/input")).click();
        Thread.sleep(10000);

        driver.findElement(By.id("listingQuestion")).click();
        Thread.sleep(10000);

        driver.findElement(By.id("listingQuestion")).sendKeys("where is the listing located");
        Thread.sleep(10000);
        driver.findElement(By.name("submitq")).click();
        Thread.sleep(10000);

        driver.findElement(By.xpath("//div/div[2]/div[3]/input")).click();
        Thread.sleep(10000);

        //          
        resultDetails.setFlag(true);

    } catch (StaleElementReferenceException e) {

        if (retries < MAX_STALE_ELEMENT_RETRIES) {

            retries++;
        }

        else {

            throw e;
        }

    }
    return getvalue;

}

From source file:com.java.AppTestType_18_11_2015.java

public void VERIFYQAINAMP(WebDriver driver, String fieldText) throws FileNotFoundException {

    String field = fieldText;/*from   w w  w  . ja v  a 2 s  .  co  m*/

    try {

        // driver.findElement(By.linkText("ALL EQUIPMENT")).click();
        /* driver.navigate().to("http://e1.dev.assetnation.com/all-equipment/equipmentone-listings");
        driver.findElement(By.linkText("2")).click();
                
        Thread.sleep(10000);
                
        List <WebElement> listings = driver.findElements(By.cssSelector("a[href*='/listing?listingid']"));
                
        Random r = new Random();
         int randomValue = r.nextInt(listings.size()); //Getting a random value that is between 0 and (list's size)-1
         listings.get(randomValue).click();
        Thread.sleep(10000);*/
        NAVIGATETOLISTINGDETAILSPAGE(driver);

        getvalue = driver.findElement(By.xpath("//*[@id='ONengine']/div[7]/span")).getText();

        System.out.println(getvalue);
        // SUMAN

        driver.findElement(By.xpath("//input[@type='button' and @value='Ask it Now']")).click();
        Thread.sleep(2000);
        driver.findElement(By.id("listingQuestion")).click();
        String question = "Where is the listing located?" + Time;
        driver.findElement(By.id("listingQuestion")).sendKeys(question);
        Thread.sleep(1000);
        driver.findElement(By.name("submitq")).click();
        Thread.sleep(4000);
        driver.findElement(By.xpath("(//input[@value='OK'])[2]")).click();
        Thread.sleep(4000);

        /* driver.findElement(By.id("uname")).click();
           Thread.sleep(10000);
           driver.findElement(By.linkText("Sign Out")).click();*/
        SIGNOUT(driver);

        driver.manage().deleteAllCookies();
        driver.navigate().refresh();

        driver.get(field);
        driver.manage().deleteAllCookies();
        driver.findElement(By.id("aurid")).sendKeys("mglaz@assetnation.com");

        driver.findElement(By.id("apwd")).sendKeys("Equipment1$");
        driver.findElement(By.xpath("//input[@value='Login']")).click();

        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

        driver.findElement(By.id("userAgreementBtn")).click();

        Thread.sleep(2000);

        System.out.println("Searching for lot id : " + getvalue);
        driver.findElement(By.name("search_string")).clear();
        driver.findElement(By.name("search_string")).sendKeys(getvalue);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        ;
        driver.findElement(By.xpath("//button")).click();

        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

        driver.findElement(By.linkText("Lot Q/A")).click();

        if (driver.getPageSource().contains(question)) {
            //driver.navigate().refresh();
            resultDetails.setFlag(true);
        } else
            System.out.println("question not found in AMP");

    } catch (Exception e) {
        e.printStackTrace();
        resultDetails.setFlag(false);

        //       FileOutputStream fos = new FileOutputStream("C:/TestProject - DEV/Log File/logfile.txt");
        //        PrintStream ps = new PrintStream(fos);
        //        e.printStackTrace(ps);
    }
}

From source file:com.java.AppTestType_18_11_2015.java

public void REJECTQUES(WebDriver driver, String fieldText) {

    try {/*from  w ww  .j  a  v  a 2 s  . c o  m*/
        NAVIGATETOLISTINGDETAILSPAGE(driver);
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        getvalue = driver.findElement(By.xpath("//*[@id='ONengine']/div[7]/span")).getText();

        System.out.println(getvalue);
        // SUMAN

        driver.findElement(By.xpath("//input[@type='button' and @value='Ask it Now']")).click();
        Thread.sleep(2000);
        driver.findElement(By.id("listingQuestion")).click();
        String question = "Can You Reject This Question?";
        driver.findElement(By.id("listingQuestion")).sendKeys(question);
        Thread.sleep(1000);
        driver.findElement(By.name("submitq")).click();
        Thread.sleep(4000);
        driver.findElement(By.xpath("(//input[@value='OK'])[2]")).click();
        Thread.sleep(4000);

        /* driver.findElement(By.id("uname")).click();
        Thread.sleep(10000);
        driver.findElement(By.linkText("Sign Out")).click();*/
        SIGNOUT(driver);

        driver.manage().deleteAllCookies();
        driver.navigate().refresh();

        driver.get(fieldText);
        driver.manage().deleteAllCookies();
        driver.findElement(By.id("aurid")).sendKeys("mglaz@assetnation.com");

        driver.findElement(By.id("apwd")).sendKeys("Equipment1$");
        driver.findElement(By.xpath("//input[@value='Login']")).click();

        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

        driver.findElement(By.id("userAgreementBtn")).click();

        Thread.sleep(2000);

        System.out.println("Searching for lot id : " + getvalue);
        driver.findElement(By.name("search_string")).clear();
        driver.findElement(By.name("search_string")).sendKeys(getvalue);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        ;
        driver.findElement(By.xpath("//button")).click();

        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

        driver.findElement(By.linkText("Lot Q/A")).click();
        WebDriverWait wait = new WebDriverWait(driver, 20);
        wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Reject")));

        String ParentHandle = driver.getWindowHandle();
        driver.findElement(By.linkText("Reject")).click();
        for (String winHandle : driver.getWindowHandles()) {

            System.out.println("Entered For Loop");
            driver.switchTo().window(winHandle);
        }

        driver.findElement(By.id("id_button_rejct")).click();

        Thread.sleep(10000);

        driver.switchTo().alert().accept();
        Thread.sleep(2000);
        driver.switchTo().window(ParentHandle);

        resultDetails.setFlag(true);

    }

    catch (StaleElementReferenceException e) {

        if (retries < MAX_STALE_ELEMENT_RETRIES) {

            retries++;
        }

        else {

            throw e;
        }
    } catch (Exception e) {

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

From source file:com.java.AppTestType_18_11_2015.java

public void FORWARDTOMM(WebDriver driver, String fieldText) {

    try {//from   w w w .  ja  va 2  s . c  o m

        NAVIGATETOLISTINGDETAILSPAGE(driver);
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        getvalue = driver.findElement(By.xpath("//*[@id='ONengine']/div[7]/span")).getText();

        System.out.println(getvalue);
        // SUMAN

        driver.findElement(By.xpath("//input[@type='button' and @value='Ask it Now']")).click();
        Thread.sleep(2000);
        driver.findElement(By.id("listingQuestion")).click();
        String question = "Could you forward my question to MM?";
        driver.findElement(By.id("listingQuestion")).sendKeys(question);
        Thread.sleep(1000);
        driver.findElement(By.name("submitq")).click();
        Thread.sleep(4000);
        driver.findElement(By.xpath("(//input[@value='OK'])[2]")).click();
        Thread.sleep(4000);

        /* driver.findElement(By.id("uname")).click();
        Thread.sleep(10000);
        driver.findElement(By.linkText("Sign Out")).click();*/
        SIGNOUT(driver);

        driver.manage().deleteAllCookies();
        driver.navigate().refresh();

        driver.get(fieldText);
        driver.manage().deleteAllCookies();
        driver.findElement(By.id("aurid")).sendKeys("mglaz@assetnation.com");

        driver.findElement(By.id("apwd")).sendKeys("Equipment1$");
        driver.findElement(By.xpath("//input[@value='Login']")).click();

        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

        driver.findElement(By.id("userAgreementBtn")).click();

        Thread.sleep(2000);

        System.out.println("Searching for lot id : " + getvalue);
        driver.findElement(By.name("search_string")).clear();
        driver.findElement(By.name("search_string")).sendKeys(getvalue);
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        ;
        driver.findElement(By.xpath("//button")).click();

        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

        driver.findElement(By.linkText("Lot Q/A")).click();
        WebDriverWait wait = new WebDriverWait(driver, 20);
        wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Forward")));

        String ParentHandle = driver.getWindowHandle();
        driver.findElement(By.linkText("Forward")).click();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        ;
        for (String winHandle : driver.getWindowHandles()) {

            System.out.println("Entered For Loop");
            driver.switchTo().window(winHandle);
        }

        Thread.sleep(10000);
        driver.findElement(By.xpath("//*[contains(@onclick,'FORWARDED TO MM')]")).click();
        driver.findElement(By.id("id_button_forward")).click();

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        ;

        driver.switchTo().alert().accept();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        ;
        driver.switchTo().window(ParentHandle);

        resultDetails.setFlag(true);

    } catch (StaleElementReferenceException e) {

        if (retries < MAX_STALE_ELEMENT_RETRIES) {

            retries++;
        }

        else {

            throw e;
        }
    } catch (Exception e) {

        resultDetails.setFlag(false);
        resultDetails.setErrorMessage("MM is not displayed for this listing");
        e.printStackTrace();
    }

}