Example usage for org.openqa.selenium WebDriver findElements

List of usage examples for org.openqa.selenium WebDriver findElements

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriver findElements.

Prototype

@Override
List<WebElement> findElements(By by);

Source Link

Document

Find all elements within the current page using the given mechanism.

Usage

From source file:com.java.AppTestType_18_11_2015.java

public void EXACTINEVENTPAGE(WebDriver driver) {

    try {//from   w  ww. j av  a2s  . co  m

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

        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();
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

        String offer = driver.findElement(By.xpath("//span[2]/span[2]/div[3]/div/span")).getText();

        System.out.println(offer);

        String Max = offer.substring(1, offer.length() - 2);

        if (Max.indexOf(',') > -1) {

            System.out.println("Field has comma");
            String convert = Max.replace(",", "");

            String dot = convert.replace(".", "");
            int mymaxoffer = Integer.parseInt(dot);
            int finaladding = add + mymaxoffer;

            String convadd = String.valueOf(finaladding);

            System.out.println(convadd);

            driver.findElement(By.xpath("//span[2]/span[2]/div[3]/div[4]/span[2]/input")).click();

            Thread.sleep(10000);

            driver.findElement(By.xpath("//span[2]/span[2]/div[3]/div[3]/input")).sendKeys(convadd);

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

            driver.findElement(By.xpath("//div[5]/div[3]/input")).sendKeys(convadd);
            Thread.sleep(10000);
            driver.findElement(By.xpath("//div[5]/div[3]/button")).click();
            Thread.sleep(10000);

            boolean isPresent = driver.findElement(By.cssSelector("input.jsTermsAgree")).isDisplayed();

            if (isPresent == true) {

                driver.findElement(By.cssSelector("input.jsTermsAgree")).click();
                driver.findElement(By.xpath("//li[9]/button")).click();
                Thread.sleep(10000);
            }

            else {

                driver.findElement(By.xpath("//li[9]/button")).click();
                Thread.sleep(10000);

            }

        }

        else {

            System.out.println("field does not have comma");

            String mydot = Max.replace(".", "");

            System.out.println(mydot);

            int mymaxoffer = Integer.parseInt(mydot);
            int finaladding = add + mymaxoffer;

            String convadd = String.valueOf(finaladding);

            driver.findElement(By.xpath("//span[2]/span[2]/div[3]/div[4]/span[2]/input")).click();

            Thread.sleep(10000);

            driver.findElement(By.xpath("//span[2]/span[2]/div[3]/div[3]/input")).sendKeys(convadd);

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

            driver.findElement(By.xpath("//div[5]/div[3]/input")).sendKeys(convadd);

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

            boolean isPresent = driver.findElement(By.cssSelector("input.jsTermsAgree")).isDisplayed();

            if (isPresent == true) {

                driver.findElement(By.cssSelector("input.jsTermsAgree")).click();
                driver.findElement(By.xpath("//li[9]/button")).click();
                Thread.sleep(10000);
            }

            driver.findElement(By.xpath("//li[9]/button")).click();
            Thread.sleep(10000);

        }

        resultDetails.setFlag(true);

    } catch (Exception e) {

        resultDetails.setFlag(false);
        resultDetails.setErrorMessage("Listing is not available or Closed");
    }

}

From source file:com.java.AppTestType_18_11_2015.java

public void BROWSEALLLISTINGS(WebDriver driver, String fieldText) { // code need to be updated if RBA do not have ',' in count.

    String fieldType = fieldText;
    String field = fieldText;// w  ww . j  a v a  2 s  .  c om
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    try {
        AppKeyWords cdf = AppKeyWords.valueOf(fieldType.toUpperCase());

        switch (cdf) {

        case BROWSEALL:
            try {

                ALLEQUIPMENTPAGE(driver);
                Thread.sleep(2500);
                driver.findElement(By.xpath("(//*[contains(@class,'source-site')]/a)[2]")).click();
                Thread.sleep(1000);
                driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
                String E1Count = driver.findElement(By.xpath("(//span[@class='e1Count'])[2]")).getText();
                String RBACount = driver.findElement(By.xpath("(//*[@class='rbaCount'])[2]")).getText();
                String SSCount = driver.findElement(By.xpath("(//*[@class='salvagesaleCount'])[2]")).getText();

                String EOCount1 = E1Count.substring(E1Count.indexOf("(") + 1, E1Count.lastIndexOf(")"));
                String RBACount1 = RBACount.substring(RBACount.indexOf("(") + 1, RBACount.lastIndexOf(")"));
                String SSCount1 = SSCount.substring(SSCount.indexOf("(") + 1, SSCount.lastIndexOf(")"));
                System.out.println("EOCount1:" + EOCount1);
                System.out.println("RBACount1:" + RBACount1);
                System.out.println("SSCount1:" + SSCount1);
                Integer E1 = Integer.parseInt(EOCount1);
                Integer RBA = Integer.parseInt(RBACount1);
                Integer SS = Integer.parseInt(SSCount1);
                int count1 = E1 + RBA + SS;
                String SearchFinalCount = String.valueOf(count1);

                String LotCount = driver.findElement(By.id("e1NumFound")).getText();
                String EventCount = driver.findElement(By.id("e1ResultsFound")).getText();
                String AuctionCount = driver.findElement(By.id("e1AuctionsFound")).getText();

                String LotCount1 = LotCount.replace(",", "");
                String EventCount1 = EventCount.replace(",", "");
                String AuctionCount1 = AuctionCount.replace(",", "");

                int Lots = Integer.parseInt(LotCount1);
                int Events = Integer.parseInt(EventCount1);
                int Auctions = Integer.parseInt(AuctionCount1);

                int myfinalcount = Lots + Events + Auctions;
                String ResultsFinalCount = String.valueOf(myfinalcount);

                System.out.println("myfinalcount:" + myfinalcount);
                System.out.println("count1:" + count1);

                //if(EOCount.equalsIgnoreCase(compfinalcount)) {   //suman

                if (count1 <= 0 || myfinalcount <= 0 || count1 != myfinalcount)
                    resultDetails.setFlag(false);

                else
                    resultDetails.setFlag(true);
            }

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

            break;

        case BROWSEE1:

            try {

                //////*    System.out.println("clicking on 1 link");
                ALLEQUIPMENTPAGE(driver);
                Thread.sleep(2500);
                //driver.findElement(By.xpath("(//a[contains(text(),'EquipmentOne Lots')])[2]")).click();
                driver.findElement(By.xpath("(//*[contains(@class,'source-site')]/a)[2]")).click();
                Thread.sleep(1000);
                driver.findElement(By.xpath("(//*[@id='site_id:RBA']/span[1]/input)[2]")).click();
                Thread.sleep(2000);
                driver.findElement(By.xpath("(//*[@id='site_id:SS']/span[1]/input)[2]")).click();

                //suman

                Thread.sleep(5000);
                driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
                String E1Count = driver.findElement(By.xpath("(//span[@class='e1Count'])[2]")).getText();
                System.out.println(E1Count);
                String EOCount = E1Count.substring(E1Count.indexOf("(") + 1, E1Count.lastIndexOf(")"));
                Integer count1 = Integer.parseInt(EOCount);
                System.out.println("count1 is: " + count1);

                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 nextlistingcount = driver.findElement(By.id("e1ResultsFound")).getText();

                //System.out.println(nextlistingcount);
                String listingcount2 = listingcount.replace(",", "");
                String nextlistingcount2 = nextlistingcount.replace(",", "");
                int convlistingcount = Integer.parseInt(listingcount2);
                int convnextlistingcount = Integer.parseInt(nextlistingcount2);

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

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

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

                //if(EOCount.equalsIgnoreCase(compfinalcount)) {   //suman

                if (count1 <= 0 || myfinalcount <= 0 || count1 != myfinalcount)
                    resultDetails.setFlag(false);

                else
                    resultDetails.setFlag(true);

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

            break;

        case MYEVENTS:
            try {

                SUBCATEGORYSELECTION(driver,
                        "XPH//*[@class='dropdown mega navBarText']/a[starts-with(text(),'All Equipment')]",
                        "XPH//*[@class='mega-nav level1']/li/a[starts-with(text(),'Events')]");
                Thread.sleep(2500);
                driver.findElement(By.xpath("(//*[contains(@class,'source-site')]/a)[2]")).click();
                Thread.sleep(1000);
                driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
                String E1Count = driver.findElement(By.xpath("(//span[@class='e1Count'])[2]")).getText();

                String EOCount1 = E1Count.substring(E1Count.indexOf("(") + 1, E1Count.lastIndexOf(")"));
                System.out.println("EOCount1:" + EOCount1);

                Integer E1 = Integer.parseInt(EOCount1);

                int count1 = E1;
                String SearchFinalCount = String.valueOf(count1);

                String EventCount = driver.findElement(By.id("e1ResultsFound")).getText();

                String EventCount1 = EventCount.replace(",", "");

                int Events = Integer.parseInt(EventCount1);

                int myfinalcount = Events;
                String ResultsFinalCount = String.valueOf(myfinalcount);

                System.out.println("myfinalcount:" + myfinalcount);
                System.out.println("count1:" + count1);

                //if(EOCount.equalsIgnoreCase(compfinalcount)) {   //suman

                if (count1 <= 0 || myfinalcount <= 0 || count1 != myfinalcount)
                    resultDetails.setFlag(false);

                else
                    resultDetails.setFlag(true);
            }

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

            break;

        }
    } 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  a  v a  2s .c  om
    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 String QA(WebDriver driver) throws FileNotFoundException, InterruptedException {

    try {/*from   w  w w.  ja  v a 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 MAXOFFERINDETAILSPAGE(WebDriver driver) {

    try {/*w w  w . ja  v a2  s . c  o m*/

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

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

        // Loops through the listings in search results page and clicks the first listing available on the page.

        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);

        String offer = driver.findElement(By.xpath("//span/div[2]/div/span")).getText();

        System.out.println(offer);

        String Max = offer.substring(1, offer.length() - 2);

        if (Max.indexOf(',') > -1) {

            System.out.println("Field has comma");
            String convert = Max.replace(",", "");

            String dot = convert.replace(".", "");
            int mymaxoffer = Integer.parseInt(dot);
            int finaladding = add + mymaxoffer;

            String convadd = String.valueOf(finaladding);

            System.out.println(convadd);

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

            driver.findElement(By.cssSelector("input.jsOfferInput")).sendKeys(convadd);

            WebDriverWait wait = new WebDriverWait(driver, 40000);

            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[3]/button")));

            driver.findElement(By.xpath("//div[3]/button")).click();

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

            driver.findElement(By.cssSelector("input.jsOfferInput.e1ConfirmInput")).sendKeys(convadd);

            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[5]/div[3]/button")));

            driver.findElement(By.xpath("//div[5]/div[3]/button")).click();

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

            boolean isPresent = driver.findElement(By.cssSelector("input.jsTermsAgree")).isDisplayed();

            if (isPresent == true) {

                driver.findElement(By.cssSelector("input.jsTermsAgree")).click();
                driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
                driver.findElement(By.xpath("//li[9]/button")).click();
                Thread.sleep(10000);
            }

            else {

                driver.findElement(By.xpath("//li[9]/button")).click();
                Thread.sleep(10000);

            }
        }

        else {

            System.out.println("field does not have comma");

            String mydot = Max.replace(".", "");

            System.out.println(mydot);

            int getmaxoffer = Integer.parseInt(mydot);
            int addingfinal = add + getmaxoffer;

            String myconvadd = String.valueOf(addingfinal);

            driver.findElement(By.xpath("//div[3]/input")).sendKeys(myconvadd);

            WebDriverWait wait = new WebDriverWait(driver, 30);

            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[3]/button")));

            driver.findElement(By.xpath("//div[3]/button")).click();

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

            driver.findElement(By.xpath("//div[5]/div[3]/input")).sendKeys(myconvadd);

            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[5]/div[3]/button")));

            driver.findElement(By.xpath("//div[5]/div[3]/button")).click();

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

            boolean isPresent = driver.findElement(By.cssSelector("input.jsTermsAgree")).isDisplayed();

            if (isPresent == true) {

                driver.findElement(By.cssSelector("input.jsTermsAgree")).click();
                driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
                driver.findElement(By.xpath("//li[9]/button")).click();
                Thread.sleep(10000);
            } else {

                Thread.sleep(10000);
                driver.findElement(By.xpath("//li[9]/button")).click();
                Thread.sleep(10000);

            }
        }

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

    try {// w  ww. ja  va  2s .  c om

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

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

        // Loops through the listings in search results page and clicks the first listing available on the page.
        // suman
        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);
        String offer = driver.findElement(By.xpath("//span/div[2]/div/span")).getText();

        System.out.println(offer);

        String Max = offer.substring(1, offer.length() - 2);

        ListingsID = driver.findElement(By.xpath("//div[7]/span")).getText();

        if (Max.indexOf(',') > -1) {

            System.out.println("Field has comma");
            String convert = Max.replace(",", "");

            String dot = convert.replace(".", "");

            System.out.println(dot);

            int mymaxoffer = Integer.parseInt(dot);
            int finaladding = add + mymaxoffer;

            String convadd = String.valueOf(finaladding);

            driver.findElement(By.xpath("//span[2]/input")).click();

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

            driver.findElement(By.xpath("//div[3]/input")).sendKeys(convadd);

            WebDriverWait wait = new WebDriverWait(driver, 30);

            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[3]/input")));

            driver.findElement(By.xpath("//div[3]/button")).click();

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

            driver.findElement(By.xpath("//div[5]/div[3]/input")).sendKeys(convadd);

            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[5]/div[3]/input")));

            driver.findElement(
                    By.cssSelector("div.e1ConfirmButton button.e1Buttons.jsConfirmOffer.e1OrangeShadow"))
                    .click();
            Thread.sleep(20000);

            boolean isPresent = driver.findElement(By.cssSelector("input.jsTermsAgree")).isDisplayed();

            if (isPresent == true) {

                driver.findElement(By.cssSelector("input.jsTermsAgree")).click();

                wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//li[9]/button")));

                driver.findElement(By.xpath("//li[9]/button")).click();
                Thread.sleep(10000);
            }

            else {

                driver.findElement(By.xpath("//li[9]/button")).click();
                Thread.sleep(10000);

            }

        }

        else {

            System.out.println("field does not have comma");

            String mydot = Max.replace(".", "");

            System.out.println(mydot);

            int mymaxoffer = Integer.parseInt(mydot);
            int finaladding = add + mymaxoffer;

            String convadd = String.valueOf(finaladding);

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

            driver.findElement(By.xpath("//div[3]/input")).sendKeys(convadd);

            WebDriverWait wait = new WebDriverWait(driver, 30);

            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[3]/input")));

            driver.findElement(
                    By.cssSelector("div.e1OfferButton.jsOfferLive button.e1Buttons.e1OrangeShadow.jsMakeOffer"))
                    .click();

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

            driver.findElement(By.xpath("//div[5]/div[3]/input")).sendKeys(convadd);

            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[5]/div[3]/input")));

            driver.findElement(
                    By.cssSelector("div.e1ConfirmButton button.e1Buttons.jsConfirmOffer.e1OrangeShadow"))
                    .click();
            Thread.sleep(20000);

            boolean isPresent = driver.findElement(By.cssSelector("input.jsTermsAgree")).isDisplayed();

            if (isPresent == true) {

                driver.findElement(By.cssSelector("input.jsTermsAgree")).click();

                wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//li[9]/button")));

                driver.findElement(By.xpath("//li[9]/button")).click();

                Thread.sleep(10000);
            } else {

                driver.findElement(By.xpath("//li[9]/button")).click();

                Thread.sleep(10000);
            }
        }
        resultDetails.setFlag(true);

    }

    catch (StaleElementReferenceException e) {

        if (retries < MAX_STALE_ELEMENT_RETRIES) {

            retries++;
        }

        else {

            throw e;
        }
    }

    catch (Exception e) {

        resultDetails.setFlag(false);
    }

}

From source file:com.java.AppTestType_18_11_2015.java

public void MAXOFFERINSEARCHRESULTSPAGE(WebDriver driver) {

    try {/*from  ww w.ja  v  a2  s.c o  m*/

        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.navigate().to("http://e1.dev.assetnation.com/all-equipment/equipmentone-listings");

        Thread.sleep(1000);
        driver.findElement(By.linkText("2")).click();//To go to 2nd page of the search results
        Thread.sleep(10000);

        //in search result there may be events, so finding first listing(excluding events) to offer exact bid

        List<WebElement> listings = driver.findElements(By.cssSelector("a[href*='/listing?listingid']"));
        int j = -1;
        for (int i = 1; i < listings.size(); i++) {
            j++;
            String s1 = listings.get(i).getAttribute("href");
            String s2[] = s1.split("/listing?");
            String s3[] = s2[1].split("&");
            String s4[] = s3[0].split("=");
            String id = s4[1];
            System.out.println("listing id is: " + id);
            System.out.println("listing-" + id);
            String listingText = driver.findElement(By.id("listing-" + id)).getText();
            //String Text[]=listingText.split("\n");
            System.out.println("text in listing is:................... " + listingText);
            if (listingText.contains("MAX BID")) {
                break;
            }

            i++;

        }

        System.out.println("number of listings in page: " + listings.size());

        //taking first listing (not concidering events)
        WebElement we = listings.get(j);
        String href = we.getAttribute("href");
        System.out.println("href of first listing is: " + href);
        // (//a[@href='http://e1.dev.assetnation.com/listing?listingid=316696&backToSearchButton=1']/following::*[@class='jsMinOfferjsAmountText'])[1]

        if (href.contains("http://e1.dev.assetnation.com"))
            href = href.replaceAll("http://e1.dev.assetnation.com", "");
        else if (href.contains("http://e1.dev.assetnation.com/"))
            href = href.replaceAll("http://e1.dev.assetnation.com/", "");

        String min_offer = driver
                .findElement(By
                        .xpath("(//a[@href='" + href + "']/following::*[@class='jsMinOffer jsAmountText'])[1]"))
                .getText();
        String min_offer2 = min_offer.substring(1, min_offer.length() - 3);
        String min_offer3 = min_offer2.replace(",", "");

        Integer minOffer = Integer.parseInt(min_offer3);
        System.out.println("minimum offer is: " + minOffer);
        Integer bidAmount = add + minOffer;
        String bidValue = String.valueOf(bidAmount);
        //clicking on Place a Bid button

        driver.findElement(
                By.xpath("(//a[@href='" + href + "']/following::*[@type='text' and @name='makeoffer'])[1]"))
                .clear();
        driver.findElement(
                By.xpath("(//a[@href='" + href + "']/following::*[@type='text' and @name='makeoffer'])[1]"))
                .sendKeys(bidValue);
        driver.findElement(By
                .xpath("(//a[@href='" + href + "']/following::*[@type='button' and @value='PLACE A BID'])[1]"))
                .click();
        Thread.sleep(2000);
        driver.findElement(By.xpath("(//a[@href='" + href
                + "']/following::*[@class='form-control jsOfferInput e1ConfirmInput' and@type='text'])[1]"))
                .sendKeys(bidValue);
        // String ss=driver.findElement(By.xpath("(//a[@href='"+href+"']/following::*[@class='form-control jsOfferInput'])[1]")).getText();

        driver.findElement(
                By.xpath("(//a[@href='" + href + "']/following::*[@type='button' and @value='CONTINUE'])[1]"))
                .click();
        Thread.sleep(2000);
        driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
        //some times we have confirmation check-box and some times we dont have
        try {
            driver.findElement(By.xpath("(//input[@class='jsTermsAgree' and @type='checkbox'])[2]")).click();
        } catch (Exception e) {
            System.out.println("there is no confirm check box");
        }
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.findElement(
                By.xpath("(//a[@href='" + href + "']/following::*[@type='submit' and @value='Submit'])[1]"))
                .click();
        Thread.sleep(2000);
        for (int i = 0; i < 20; i++) {
            if (driver
                    .findElement(
                            By.xpath("(//a[@href='" + href + "']/following::*[@class='jsMyMaxBidValue'])[1]"))
                    .getText().contains("$"))
                break;
            Thread.sleep(500);
        }
        String MyMaxBid = driver
                .findElement(By.xpath("(//a[@href='" + href + "']/following::*[@class='jsMyMaxBidValue'])[1]"))
                .getText();
        String MyMaxBid2 = MyMaxBid.replace(".00", ""); //$8,200.00
        String MyMaxBid3 = MyMaxBid2.replace("$", "").replace(",", "");

        System.out.println("bidded value is: " + bidValue);
        System.out.println("showing my bid value is: " + MyMaxBid3);
        if (MyMaxBid3.equals(bidValue))
            resultDetails.setFlag(true);
        else
            System.out.println("bid value is mis-matched");

    }

    catch (Exception e) {

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

}

From source file:com.java.AppTestType_18_11_2015.java

public void EXACTOFFERINSEARCHRESULTSPAGE(WebDriver driver) {

    try {/*from  w  ww.  j  a  v  a2 s .  co m*/
        // suman 
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.navigate().to("http://e1.dev.assetnation.com/all-equipment/equipmentone-listings");

        Thread.sleep(1000);
        driver.findElement(By.linkText("2")).click();//To go to 2nd page of the search results
        Thread.sleep(10000);

        //in search result there may be events, so finding first listing(excluding events) to offer exact bid

        List<WebElement> listings = driver.findElements(By.cssSelector("a[href*='/listing?listingid']"));
        int j = -1;
        for (int i = 1; i < listings.size(); i++) {
            j++;
            String s1 = listings.get(i).getAttribute("href");
            String s2[] = s1.split("/listing?");
            String s3[] = s2[1].split("&");
            String s4[] = s3[0].split("=");
            String id = s4[1];
            System.out.println("listing id is: " + id);
            System.out.println("listing-" + id);
            String listingText = driver.findElement(By.id("listing-" + id)).getText();
            //String Text[]=listingText.split("\n");
            System.out.println("text in listing is:................... " + listingText);
            if (listingText.contains("MAX BID")) {
                break;
            }

            i++;

        }

        System.out.println("number of listings in page: " + listings.size());

        //taking first listing (not concidering events)
        WebElement we = listings.get(j);
        String href = we.getAttribute("href");
        System.out.println("href of first listing is: " + href);
        // (//a[@href='http://e1.dev.assetnation.com/listing?listingid=316696&backToSearchButton=1']/following::*[@class='jsMinOfferjsAmountText'])[1]

        if (href.contains("http://e1.dev.assetnation.com"))
            href = href.replaceAll("http://e1.dev.assetnation.com", "");
        else if (href.contains("http://e1.dev.assetnation.com/"))
            href = href.replaceAll("http://e1.dev.assetnation.com/", "");

        String min_offer = driver
                .findElement(By
                        .xpath("(//a[@href='" + href + "']/following::*[@class='jsMinOffer jsAmountText'])[1]"))
                .getText();
        String min_offer2 = min_offer.substring(1, min_offer.length() - 3);
        String min_offer3 = min_offer2.replace(",", "");

        Integer minOffer = Integer.parseInt(min_offer3);
        System.out.println("minimum offer is: " + minOffer);
        Integer bidAmount = add + minOffer;
        String bidValue = String.valueOf(bidAmount);
        //clicking on exact bid radio button
        driver.findElement(By.xpath(
                "(//a[@href='" + href + "']/following::*[@class='check-box' and @value='Exact Bid'])[1]"))
                .click();
        driver.findElement(
                By.xpath("(//a[@href='" + href + "']/following::*[@type='text' and @name='makeoffer'])[1]"))
                .clear();
        driver.findElement(
                By.xpath("(//a[@href='" + href + "']/following::*[@type='text' and @name='makeoffer'])[1]"))
                .sendKeys(bidValue);
        driver.findElement(By
                .xpath("(//a[@href='" + href + "']/following::*[@type='button' and @value='PLACE A BID'])[1]"))
                .click();
        Thread.sleep(2000);
        driver.findElement(By.xpath("(//a[@href='" + href
                + "']/following::*[@class='form-control jsOfferInput e1ConfirmInput' and@type='text'])[1]"))
                .sendKeys(bidValue);
        // String ss=driver.findElement(By.xpath("(//a[@href='"+href+"']/following::*[@class='form-control jsOfferInput'])[1]")).getText();

        driver.findElement(
                By.xpath("(//a[@href='" + href + "']/following::*[@type='button' and @value='CONTINUE'])[1]"))
                .click();
        Thread.sleep(2000);
        driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
        //some times we have confirmation check-box and some times we dont have
        try {
            driver.findElement(By.xpath("(//input[@class='jsTermsAgree' and @type='checkbox'])[2]")).click();
        } catch (Exception e) {
            System.out.println("there is no confirm check box");
        }
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.findElement(
                By.xpath("(//a[@href='" + href + "']/following::*[@type='submit' and @value='Submit'])[1]"))
                .click();
        Thread.sleep(2000);
        for (int i = 0; i < 20; i++) {
            if (driver
                    .findElement(
                            By.xpath("(//a[@href='" + href + "']/following::*[@class='jsMyMaxBidValue'])[1]"))
                    .getText().contains("$"))
                break;
            Thread.sleep(500);
        }
        String MyMaxBid = driver
                .findElement(By.xpath("(//a[@href='" + href + "']/following::*[@class='jsMyMaxBidValue'])[1]"))
                .getText();
        String MyMaxBid2 = MyMaxBid.replace(".00", ""); //$8,200.00
        String MyMaxBid3 = MyMaxBid2.replace("$", "").replace(",", "");

        System.out.println("bidded value is: " + bidValue);
        System.out.println("showing my bid value is: " + MyMaxBid3);
        if (MyMaxBid3.equals(bidValue))
            resultDetails.setFlag(true);
        else
            System.out.println("bid value is mis-matched");

    }

    catch (Exception e) {

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

}

From source file:com.java.AppTestType_18_11_2015.java

public void ADDTOWATCHLIST(WebDriver driver, String fieldText) {

    String fieldType = fieldText;
    String field = fieldText;/*from  www.j av  a  2  s .c  om*/
    try {
        AppKeyWords cdf = AppKeyWords.valueOf(fieldType.toUpperCase());

        switch (cdf) {

        case FROMSEARCH:

            try {

                driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
                WebDriverWait wait = new WebDriverWait(driver, 25);
                //navigation to next page
                driver.findElement(By.linkText("2")).click();
                //Thread.sleep(5000)
                wait.until(ExpectedConditions
                        .presenceOfElementLocated(By.xpath("(//*[@class='e1tooltip icon_watchlist'])[1]")));
                //clicking on first binocular icon which is not yet watching
                ListingID = driver.findElement(By.xpath(
                        "(//*[@class='e1tooltip icon_watchlist']/../following::div[@class='rgbold jsLotID myone-black'])[2]"))
                        .getText();
                System.out.println(ListingID);
                driver.findElement(By.xpath("(//*[@class='e1tooltip icon_watchlist'])[1]")).click();
                Thread.sleep(1000);
                resultDetails.setFlag(true);
            }

            catch (Exception e) {

                resultDetails.setFlag(false);
            }

            break;

        case FROMLISTING:
            try {
                driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

                driver.findElement(By.linkText("2")).click();//To go to 2nd page of the search results

                driver.findElement(By.xpath("(//*[@class='e1tooltip icon_watchlist']/../../a[1])[1]")).click();
                ;
                //ListingID = driver.findElement(By.xpath("//*[contains(text(),'Lot ID:')]/span")).getText(); 
                ListingID = driver.findElement(By.xpath("//*[@class='e2lot-result rgbold jsLotID']")).getText();
                System.out.println(ListingID);

                driver.findElement(By.linkText("Watch This")).click();
                System.out.println("clicked on watch this");

                System.out.println(driver.findElement(By.xpath("//*[@class='e1WatchingThisText']")).getText());
                if (driver.findElement(By.xpath("//*[@class='e1WatchingThisText']")).getText()
                        .equalsIgnoreCase("Watching")) {
                    System.out.println("Added to watchlist");
                    resultDetails.setFlag(true);
                } else {
                    resultDetails.setFlag(false);
                    System.out.println("listing is not added to watchlist1");
                }
                System.out.println("going out of ADDTOWATCHLIST method");

            }

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

            break;

        case FROMEVENTPAGE:
            try {
                driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
                List<WebElement> events = driver
                        .findElements(By.xpath("//a[@class='jsTitle' and contains(@href,'/event?eventid')]"));
                System.out.println("event size is: " + events.size());
                Random r = new Random();
                /*int randomValue = r.nextInt(listings.size()); //Getting a random value that is between 0 and (list's size)-1
                */ WebDriverWait wait = new WebDriverWait(driver, 20);

                //selecting random event and trying to bid on first listing, if the event doesn't have open listings it will try with next event
                for (int i = 0; i < events.size(); i++) {
                    events.get(r.nextInt(events.size())).click();
                    Thread.sleep(8000);
                    if (driver.findElement(By.xpath("(//*[@class='e1tooltip icon_watchlist'])[1]"))
                            .isDisplayed()) {
                        //clicking on first binocular icon which is not yet watching
                        ListingID = driver.findElement(By.xpath(
                                "(//*[@class='e1tooltip icon_watchlist']/../following::div[@class='rgbold jsLotID myone-black'])[2]"))
                                .getText();
                        System.out.println(ListingID);
                        driver.findElement(By.xpath("(//*[@class='e1tooltip icon_watchlist'])[1]")).click();
                        Thread.sleep(1000);
                        resultDetails.setFlag(true);
                        break;
                    }
                    //go back to event page
                    else
                        driver.navigate().back();

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

    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("listing is not added to watchlist2");
        resultDetails.setFlag(false);
    }
}

From source file:com.java.AppTestType_18_11_2015.java

public void NAVIGATETOLISTINGDETAILSPAGE(WebDriver driver) {

    try {// w  w  w.ja  va2s .c o  m
        //suman
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.navigate().to("http://e1.dev.assetnation.com/all-equipment/equipmentone-listings");

        Thread.sleep(1000);

        // driver.findElement(By.xpath("(//*[@class='page-dots']/following::a)[1]")).click();//To go to last page of the search results
        //navigating to second page
        driver.findElement(By.linkText("2")).click();

        Thread.sleep(10000);

        List<WebElement> listings = driver.findElements(By.cssSelector("a[href*='/listing?listingid']"));
        System.out.println("number of listings in page: " + listings.size());
        //searching for listing from search result page which may contain events also so excluding events
        for (int i = 1; i < listings.size(); i++) {

            String s1 = listings.get(i).getAttribute("href");
            String s2[] = s1.split("/listing?");
            String s3[] = s2[1].split("&");
            String s4[] = s3[0].split("=");
            String id = s4[1];
            System.out.println("listing id is: " + id);
            System.out.println("listing-" + id);
            String listingText = driver.findElement(By.id("listing-" + id)).getText();
            //String Text[]=listingText.split("\n");
            System.out.println("text in listing is:................... " + listingText);
            if (listingText.contains("MAX BID") || listingText.contains("SIGN IN TO PLACE A BID")
                    || listingText.contains("PLACE A BID")) {
                System.out.println("clicking on listing: " + ((i / 2) + 1));
                listings.get(i).click();
                break;
            }

            i++;

        }

        //waiting upto listing will be loaded
        WebDriverWait wait = new WebDriverWait(driver, 40);
        wait.until(
                ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[text()='More from This Seller']")));
        // wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@value='RETURN TO RESULTS']")));*/

        //Thread.sleep(10000);
        if (driver.findElement(By.xpath("//div[contains(@class,'e1OfferConsole')]")).isDisplayed())
            resultDetails.setFlag(true);
    } catch (Exception e) {
        e.printStackTrace();
        resultDetails.setFlag(false);

    }
}