Web page zoom in and zoom out using Selenium webdriver

import org.testng.annotations.Test;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeTest;
public class zoomINzoomOUT {
    WebDriver driver;
@Test
      public void BrowserZoomINandZoomOUT() throws Exception{
      zoomIn();
      Thread.sleep(3000);
      zoomOut();
      Thread.sleep(3000);
      defaultset();
     }
public void zoomIn()  {  //To zoom In page 5 times using CTRL and "+" keys.
           for(int i=0; i<5; i++){  
      driver.findElement(By.linkText("Selenium")).sendKeys(Keys.CONTROL, Keys.ADD);
       }
     }
public void zoomOut(){   //To zoom out page 9 times using CTRL and "-" keys.
            for(int i=0; i<9; i++){
      driver.findElement(By.linkText("Selenium")).sendKeys(Keys.CONTROL, Keys.SUBTRACT);
      }
     }
public void defaultset(){    //To set browser to default level like CTRL+0
           driver.findElement(By.linkText("Selenium")).sendKeys(Keys.CONTROL, "0");
     }
    @BeforeTest
     public void setup() {
     driver = new FirefoxDriver();
     driver.manage().window().maximize();
     driver.get("http://seleniumsubbu.blogspot.in/");
     driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
     }
}

Handle internet explorer SSL certificate issue in Selenium

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
public class SSLCertificateIE {
    WebDriver driver;
    @Test
    public void SSLIE() throws Exception {
        System.setProperty("webdriver.ie.driver","E:\\lib\\IEDriverServer.exe");
        driver=new InternetExplorerDriver();
        driver.get("https://www.seleniumlearn.com");
        driver.navigate().to("javascript:document.getElementById(‘overridelink’).click()");
        }  
  
    @BeforeTest
    public void beforeTest() {
        driver=new FirefoxDriver();
        driver.manage().window().maximize();
    }
    @AfterTest
    public void afterTest() {
    }
}

Find all the Links on a Webpage using Selenium

import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
public class TotalNumberLinks{
     public WebDriver driver;
@Test
       public void TotalNumberofLinks() throws InterruptedException {
        driver.get("http://seleniumsubbu.blogspot.in/");
        driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
        driver.manage().window().maximize();
        List<WebElement> list=driver.findElements(By.tagName("a"));
        System.out.println("Total number of links:"+ list.size());
        driver.close();
         }
@BeforeTest
  public void beforeTest() {
      driver= new FirefoxDriver();
      driver.manage().window().maximize();
  }
@AfterTest
  public void afterTest() {
  }
}

Handle Firefox SSL certificate issue in Selenium

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
public class SSLCertificateFirefox {
    WebDriver driver;
    @Test
    public void SSLFirefox() throws Exception {
        driver.get("http://seleniumsubbu.blogspot.in/");
        FirefoxProfile fp = new FirefoxProfile();
        fp.setAcceptUntrustedCertificates(true);
        fp.setAssumeUntrustedCertificateIssuer(false);
        driver=new FirefoxDriver(fp);
    }
    @BeforeTest
    public void beforeTest() {
        driver=new FirefoxDriver();
        driver.manage().window().maximize();
    }
    @AfterTest
    public void afterTest() {
    }
}

How to Webpage Scroll Down and Scroll Up using Selenium WebDriver ?

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.interactions.internal.Coordinates;
import org.openqa.selenium.internal.Locatable;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;
import com.gargoylesoftware.htmlunit.WebClient;
import org.testng.annotations.BeforeTest;
public class Scrollingonpages {
public WebDriver driver;
  
@Test (priority=1)// Scroll down
         public void ScrollDown() throws Exception {
         driver.get("http://seleniumsubbu.blogspot.in/");
         driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
         JavascriptExecutor jse = (JavascriptExecutor)driver;
         jse.executeScript("scroll(0, 900)"); // Y value is scroll down
         Thread.sleep(5000);      
    }
@Test (priority=2)// Scroll up
       public void ScrollUP() throws Exception {
       driver.get("http://seleniumsubbu.blogspot.in/");
       driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
       JavascriptExecutor jse = (JavascriptExecutor)driver;
       jse.executeScript("scroll(900, 0)"); // Y value is scroll down
  }
@Test (priority=3)//Infinite Scrill Down
        public void InfiniteScrillDown() throws Exception {
        driver.get("http://seleniumsubbu.blogspot.in/");
        driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
       {
        Thread.sleep(1000);
        JavascriptExecutor jse = (JavascriptExecutor)driver;
        jse.executeScript("window.scrollTo(0,Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight));");
   }
   }
@Test  (priority=4)// Infinite Scroll
        public void InfiniteScroll() throws Exception {
        driver.get("http://seleniumsubbu.blogspot.in/");
        driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
        Actions act = new Actions(driver);
        for(int i=0;i<=25;i++)
       {
        Thread.sleep(1000);
        //driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
       act.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform();   // Shourtcut key for Infinite scroll (Ctrl+End)
       }
}
@Test (priority=5)// Continious Scrolling
       public void ContiniousScrolling() throws Exception {
       driver.get("http://seleniumsubbu.blogspot.in/");
       driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
      {
      for(int i=0;i<25;i++)
      {
      //driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS); // It will scroll speed
      Thread.sleep(1000);
      driver.findElement(By.tagName("body")).sendKeys(Keys.DOWN); // wait for 1 second and Scrool
      }
      } 
      }  
@Test (priority=6)// //Indentify Loacator Element
        public void IndentifyLoacatorElement() throws Exception {
        driver.get("http://seleniumsubbu.blogspot.in/");
        driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
        {
            WebClient element = (WebClient) driver.findElement(By.xpath("//*[@id='test']/p[10]/a"));
            Coordinates coordinate = ((Locatable)element).getCoordinates();
            coordinate.onPage();
            coordinate.inViewPort();
             }  
          }
@BeforeTest
         public void beforeTest() {
         driver = new FirefoxDriver();
         driver.manage().window().maximize();
       }
@AfterTest
       public void afterTest() {
  }
}

Find all the Links on a Webpage using Selenium

import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
public class TotalNumberLinks{
     public WebDriver driver;
@Test
       public void TotalNumberofLinks() throws InterruptedException {
        driver.get("http://seleniumsubbu.blogspot.in/");
        driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
        driver.manage().window().maximize();
        List<WebElement> list=driver.findElements(By.tagName("a"));
        System.out.println("Total number of links:"+ list.size());
        driver.close();
         }
@BeforeTest
  public void beforeTest() {
      driver= new FirefoxDriver();
      driver.manage().window().maximize();
  }
@AfterTest
  public void afterTest() {
  }
}

How to handle conformation prompt dialog box using selenium webdriver ?

import org.testng.annotations.Test;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeTest;
public class ConformationAlertCanel {
    public WebDriver driver;
@Test
     public void ConformationAlertBox()throws Exception {
     driver.get("http://seleniumsubbu.blogspot.in/");
     driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
     driver.findElement(By.xpath("//*[@id='node-102']/div/div[1]/div/div/button")).click();
     Thread.sleep(5000);
     //driver.switchTo().alert().accept();//    accept means :click on "OK" option button
     driver.switchTo().alert().dismiss();  // dismiss means : click on "Cancel" option button
     }
@BeforeTest
     public void beforeTest() {
     driver= new FirefoxDriver();
     driver.manage().window().maximize();
     }
}

how to handle alert prompt dialog box using selenium webdriver ?

import org.testng.annotations.Test;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeTest;
public class AlertOk {
     public WebDriver driver;
   
@Test
            public void Alert()throws Exception {
            driver.get("http://seleniumsubbu.blogspot.in/");
            driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
            driver.findElement(By.xpath("//*[@id='node-100']/div/div[1]/div/div/button")).click();
            Thread.sleep(5000);
            driver.switchTo().alert().accept();  
            }
@BeforeTest
            public void beforeTest() {
            driver= new FirefoxDriver();
            }
}

Double click using selenium

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
public class DoubleClick {
    WebDriver driver;
  
    @Test
    public void Doubleclick() throws Exception {
    driver.get("http://seleniumsubbu.blogspot.in/");
    Thread.sleep(9000);
    Actions act = new Actions(driver);
    act.moveToElement(driver.findElement(By.xpath("//*[@id='node-104']/div/div[1]/div/div/button"))).doubleClick().perform();
    }
  @BeforeTest
  public void beforeTest() {
      driver=new FirefoxDriver();
      driver.manage().window().maximize();
  }
  @AfterTest
  public void afterTest() {
  }
}

How to take screenshot for only failed test cases using selenium web driver ?

import org.testng.annotations.Test;
import org.openqa.selenium.TakesScreenshot;
import java.io.File;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.BeforeTest;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
public class TakeScreenshot {
public WebDriver driver;              
@Test (description="take Screenshots if Test Case fails")
       public void TakeScreenshot() throws Exception {    
         driver.get("http://seleniumsubbu.blogspot.in/");
     try {              
             driver.findElement(By.id("xyz")).click();
           }
    catch(Exception e) {    
             System.out.println("Element Not Found");  
             takeScreenshot();    
          }    
       }
     public void takeScreenshot() throws Exception {            
          File f = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
          FileUtils.copyFile(f, new File("/home/chinna/selenium/seleniumSubbu.png")); //Linux path  
          // FileUtils.copyFile(f, new File("E:\\Workspace\\SeleniumSubbu.png"));          // for windows  path
       }
@BeforeTest
     public void beforeTest() {
      driver = new FirefoxDriver();
      driver.manage().window().maximize();
  }
@AfterTest
  public void afterTest() {
  }
}

How to Webpage Scroll Down and Scroll Up using Selenium WebDriver ?

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.interactions.internal.Coordinates;
import org.openqa.selenium.internal.Locatable;
import org.testng.annotations.AfterTest;
import org.testng.annotations.Test;
import com.gargoylesoftware.htmlunit.WebClient;
import org.testng.annotations.BeforeTest;
public class Scrollingonpages {
public WebDriver driver;
  
@Test (priority=1)// Scroll down
         public void ScrollDown() throws Exception {
         driver.get("http://seleniumsubbu.blogspot.in/");
         driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
         JavascriptExecutor jse = (JavascriptExecutor)driver;
         jse.executeScript("scroll(0, 900)"); // Y value is scroll down
         Thread.sleep(5000);      
    }
@Test (priority=2)// Scroll up
       public void ScrollUP() throws Exception {
       driver.get("http://seleniumsubbu.blogspot.in/");
       driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
       JavascriptExecutor jse = (JavascriptExecutor)driver;
       jse.executeScript("scroll(900, 0)"); // Y value is scroll down
  }
@Test (priority=3)//Infinite Scrill Down
        public void InfiniteScrillDown() throws Exception {
        driver.get("http://seleniumsubbu.blogspot.in/");
        driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
       {
        Thread.sleep(1000);
        JavascriptExecutor jse = (JavascriptExecutor)driver;
        jse.executeScript("window.scrollTo(0,Math.max(document.documentElement.scrollHeight,document.body.scrollHeight,document.documentElement.clientHeight));");
   }
   }
@Test  (priority=4)// Infinite Scroll
        public void InfiniteScroll() throws Exception {
        driver.get("http://seleniumsubbu.blogspot.in/");
        driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
        Actions act = new Actions(driver);
        for(int i=0;i<=25;i++)
       {
        Thread.sleep(1000);
        //driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
       act.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform();   // Shourtcut key for Infinite scroll (Ctrl+End)
       }
}
@Test (priority=5)// Continious Scrolling
       public void ContiniousScrolling() throws Exception {
       driver.get("http://seleniumsubbu.blogspot.in/");
       driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
      {
      for(int i=0;i<25;i++)
      {
      //driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS); // It will scroll speed
      Thread.sleep(1000);
      driver.findElement(By.tagName("body")).sendKeys(Keys.DOWN); // wait for 1 second and Scrool
      }
      } 
      }  
@Test (priority=6)// //Indentify Loacator Element
        public void IndentifyLoacatorElement() throws Exception {
        driver.get("http://seleniumsubbu.blogspot.in/");
        driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
        {
            WebClient element = (WebClient) driver.findElement(By.xpath("//*[@id='test']/p[10]/a"));
            Coordinates coordinate = ((Locatable)element).getCoordinates();
            coordinate.onPage();
            coordinate.inViewPort();
             }  
          }
@BeforeTest
         public void beforeTest() {
         driver = new FirefoxDriver();
         driver.manage().window().maximize();
       }
@AfterTest
       public void afterTest() {
  }
}

How to right click on a link and select an option using Selenium WebDriver ?

import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.testng.annotations.AfterTest;
public class RightClick {
    public class Rightclick {
          public WebDriver driver;
      
      @Test //Right Click on Link,Button and Image etc.. using Selenium Webdriver
           public void RightClick() throws Exception {
           driver.get("http://seleniumsubbu.blogspot.in/");
           Thread.sleep(5000);
           Actions act=new Actions(driver);
           act.contextClick(driver.findElement(By.linkText("Git"))).perform();
           }
      @BeforeTest
          public void beforeTest() {
          driver = new FirefoxDriver();
          driver.manage().window().maximize();
          }
      @AfterTest
         public void afterTest() {
           }
                }
           }

How to take Full page Screenshot using Selenium ?

import java.io.File; 
import java.text.DateFormat; 
import java.text.SimpleDateFormat; 
import java.util.Date; 
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType; 
import org.openqa.selenium.TakesScreenshot; 
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.testng.annotations.Test; 
//import com.thoughtworks.selenium.Selenium; 
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
public class FullPageScreenShout {      
   public WebDriver driver;   
    //  public Selenium selenium;
 public void FullPageScreenshot() throws Exception 
{        
     DateFormat dateFormat = new SimpleDateFormat("yyyy_MMM_dd HH_mm_ss");
     Date date = new Date();  
    String time=dateFormat.format(date); 
            System.out.println(time);         
    File f = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);    
         FileUtils.copyFile(f, new File("/home/chinna/Desktop/TechLearn"+time+".png")); 
// Linux machine path          
  // FileUtils.copyFile(f, new File("E:\\Workspace\\Techlearn"+time+".png"));  
         // for windows matchine path       
      }     
   @Test
 // Print Full Screenshot     
       public void TakeScreenShot() throws Exception
{           driver.get("http://seleniumsubbu.blogspot.in/");       
    FullPageScreenshot();         
  }  
@BeforeTest  
 public void beforeTest() 
{        
    driver= new FirefoxDriver();  
    driver.manage().window().maximize();     
    } 
@AfterTest     
 public void afterTest()
 {        
    }    
      } 

How to launch chrome browser using selenium webdriver ?

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import com.thoughtworks.selenium.Selenium;
public class MyData {
    public WebDriver driver;
    public Selenium selenium;
 
    @Test
        public void LaunchChromeBrowser()
        {
        driver.get("http://seleniumsubbu.blogspot.in/");
        }
 
    @BeforeTest
        public void beforeTest()
        {
         //---> for Windows machine
        System.setProperty("webdriver.chrome.driver", "E:\\Library\\chromedriver.exe");  // Your chromedriver path.
        driver=new ChromeDriver();
       
        //---> for Linux machine
        System.setProperty("webdriver.chrome.driver",  "/home/Subbu/lib/chromedriver");   // Your chromedriver path.
        driver = new ChromeDriver();
        driver.manage().window().maximize();
        }
    @AfterTest
        public void afterTest() {
    }
}

How to launch Firefox Browser using Selenium ?

import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterTest;
public class LaunchFirefoxBrowser {
    public WebDriver driver;
  @Test
  public void LaunchFirefoxBrowser() {
      driver.get("http://seleniumsubbu.blogspot.in/");
  }
  @BeforeTest
  public void beforeTest() {
      driver= new FirefoxDriver();
  }
  @AfterTest
  public void afterTest() {
  }
}

what is Implicit, Explicit & Fluent Wait in Selenium Web driver and their difference

Implicit Wait

By using Implicit wait we can tell Selenium that we would like it to wait for a certain amount of time before throwing an exception that it cannot find the element on the page. We should note that implicit waits will be in place for the entire time the browser is open. This means that any search for elements on the page could take the time the implicit wait is set for.




 WebDriver driver = new FirefoxDriver();
 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
 driver.get("http://www.ebay.in/cat/mobiles/brand/Samsung");
 WebElement myDynamicElement = driver.findElement(By.id("myDynamicElement"));

Explicit Wait

It is more extendible in the means that you can set it up to wait for any condition you might like. Usually, you can use some of the prebuilt ExpectedConditions to wait for elements to become clickable, visible, invisible, etc.

driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait()
WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
element = wait.until(ExpectedConditions.visibilityOfElementLocated(by));

Fluent Wait

Each FluentWait instance defines the maximum amount of time to wait for a condition, as well as the frequency with which to check the condition. Furthermore, the user may configure the wait to ignore specific types of exceptions whilst waiting, such as NoSuchElementExceptions when searching for an element on the page..

FluentWait  wait = new FluentWait(driver).withTimeout(timeOutInSeconds,TimeUnit.SECONDS).pollingEvery(200,TimeUnit.MILLISECONDS)
.ignoring(NoSuchElementException.class);
        element = (WebElement) wait.until(ExpectedConditions.visibilityOfElementLocated(by));
package PageFactory; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.PageFactory; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.FluentWait; import org.openqa.selenium.support.ui.WebDriverWait; import java.util.NoSuchElementException; import java.util.concurrent.TimeUnit; /** * Created by Niraj on 2/10/2015. */ public class ConceptPage { WebDriver driver; @FindBy(xpath="//input[@type='submit' and @title='See more']") WebElement btnSeeMore; @FindBy(xpath="//div[@class='itm'][21]//div[@class='itemttl']") WebElement thelement; public static final int DEFAULT_WAIT_4_PAGE = 12; public static final int DEFAULT_WAIT_4_ELEMENT = 15; public ConceptPage(WebDriver driver){ this.driver=driver; PageFactory.initElements(driver,this); } public void verify21stElement(){ WebElement webElement = waitforElementUsingFluent(driver, By.xpath("//div[@class='itm'][21]//div[@class='itemttl']//a"), 20);
 public void  verify21stElement(){
        WebElement webElement = waitForElement
(driver, By.xpath("//div[@class='itm'][21]//div[@class='itemttl']//a"), 20);

        System.out.println("Element present : "+ webElement.getAttribute("href"));
    }


//Explicit wait function definition here...:

    public static WebElement waitForElement(WebDriver driver, final By by, int timeOutInSeconds) {
        WebElement element;
        try{
            //To use WebDriverWait(), we would have to nullify implicitlyWait().
            //Because implicitlyWait time also set "driver.findElement()" wait time.
            //info from: https://groups.google.com/forum/?fromgroups=#!topic/selenium-users/6VO_7IXylgY
            driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS); //nullify implicitlyWait()

            WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds);
            element = wait.until(ExpectedConditions.visibilityOfElementLocated(by));

            driver.manage().timeouts().implicitlyWait(DEFAULT_WAIT_4_ELEMENT, TimeUnit.SECONDS); //reset implicitlyWait
            return element; //return the element
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    
//Fluent wait function definition goes here... 

    public static WebElement waitforElementUsingFluent(WebDriver driver, By by, int timeOutInSeconds){
        
        WebElement element;
       FluentWait  wait = new FluentWait(driver).withTimeout(timeOutInSeconds,TimeUnit.SECONDS).pollingEvery(200,TimeUnit.MILLISECONDS).ignoring(NoSuchElementException.class);
        element = (WebElement) wait.until(ExpectedConditions.visibilityOfElementLocated(by));
        return element;


    }

public void clickOnSeeMore(){
    btnSeeMore.click();
}
}


// Main test goes here...


package Selenium;
import PageFactory.ConceptPage;
import PageFactory.HomePage;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.util.concurrent.TimeUnit;
*/public class LoginWithPageFactory {
    WebDriver driver;
    LoginPage loginPage;
    HomePage homePage;
    @BeforeTest    public void setup(){
        driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("http://www.ebay.in/cat/mobiles/brand/Samsung");
    }
    
    @Test(priority = 1)
    public void test_AJAX(){
        driver.get("http://www.ebay.in/cat/mobiles/brand/Samsung");
        ConceptPage conceptPage = new ConceptPage(driver);
        conceptPage.clickOnSeeMore();
        conceptPage.verify21stElement();
    }
    public void teardown(){
        driver.close();
        driver.quit();;

    }
}