Selenium Commands

 Launching Browsers :- 

  • driver=new FirefoxDriver();                              // Selenium 2 - Launching firefox browser 

                                                  // OR

  • System.setProperty("webdriver.gecko.driver","path of geckodriver.exe"); // Selenium 3 - Launching firefox browser using Geckodriver 
    WebDriver driver = new FirefoxDriver();

                          

  • System.setProperty("webdriver.chrome.driver","E:\\lib\\chromedriver.exe"); 
    driver=new ChromeDriver();

     

  • System.setProperty("webdriver.ie.driver","E:\\lib\\IEDriverServer.exe");  //--->IE for Windows path
    driver=new InternetExplorerDriver();

     

  • driver=new OperaDriver();   //--->Operabroser
     

  • driver=new SafariDriver();   //--->Operabroser

     

 Back, Forward, Navigate and Refresh :- 

1)driver.navigate().to("http://www.fb.com/seleniumtool");

2)driver.get("http://www.seleniumlearn.com");

3)driver.navigate().back();

4)driver.navigate().forward();

5)driver.navigate().refresh();

 

 Locators / Elements :- 

  • ID
    driver.findElement(By.id("gbqfq")).sendKeys("TechLearn");

  • Name
    driver.findElement(By.name("q")).sendKeys("TechLearn");

  • CSS(Cascadestylesheet)
    driver.findElement(By.cssSelector("Register")).click();

  • XPATH

             Relativexpath
                       driver.findElement(By.xpath("(//input[@id='gender'])[2]")).click();

             Absolutexpath
                       driver.findElement(By.xpath("(//div[1]/div[2]/div[1]/div[2]/button[1]")).click();

  • Classname
    driver.findElements(By.className("techlearn"));

  • TagName
    driver.findElement(By.tagName("iframe"));

  • LinkText
    driver.findElement(By.linkText("Sign-in")).click();

  • PartialLinkText

             driver.findElement(By.partialLinkText("selenium"));

                        Locators step by step Tutorial

 Close :- 

driver.close();

 Quit :- 

driver.quit();

 Clear :- 

driver.findElement(By.id("edit-submitted-first-name-")).clear();

 Get :- 

driver.get("http://www.seleniumtool.com");

 Title :- 

driver.getTitle();

 Current page URL :- 

driver.getCurrentUrl();

 

 Type :- 

driver.findElement(By.id("edit-submitted-first-name-")).sendKeys("Selenium");
                                                                                        

 Window Maximize :- 

driver.manage().window().maximize();

 Synchronization :- 

  • Thread.sleep(9000);

  • driver.manage().timeouts().implicitlyWait(9,TimeUnit.SECONDS);

  • WebDriverWaitwait=newWebDriverWait(driver,9);
    wait.until(ExpectedConditions.elementToBeClickable(By.id("element-id")));

  • selenium.waitForPageToLoad("9000");

  • selenium.setTimeout("90000");

  • driver.manage().timeouts().implicitlyWait(9,TimeUnit.SECONDS);

  • driver.manage().timeouts().pageLoadTimeout(9,TimeUnit.SECONDS);

  • Wait<WebDriver>  wait = new FluentWait<WebDriver>(driver)
    .withTimeout(30, SECONDS)
    .polingEvery(5, SECONDS)
    .ignoring(NoSuchElemntException.clas);

  • robot.delay(1000);

 Webdiver BackedSelenium :- 

Selenium = new webDriverBackedSelenium(driver, "http://www.seleniumlearn.com");

  Drag and Drop :- 

Actions act=new Actions(driver);
WebElement source=driver.findElement(By.id(“draggable”));
WebElement target=driver.findElement(By.id(“droppable”));
act.dragAndDrop(source,target).perform(); 
 

  Right click :- 

@Test
public void RightClick() throws Exception {
driver.get("http://www.techlearn.in/");
Thread.sleep(3000);
Actions act=new Actions(driver);
act.contextClick(driver.findElement(By.linkText("
Quiz"))).perform();
}

                                                                      

 Mouseover :- 

    @Test
    public void mousehover() {
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.get("http://techlearn.in");
    WebElement element = driver.findElement(By.id("menu-328-1"));
    Actions act = new Actions(driver);
    act.moveToElement(element).build().perform();

    driver.findElement(By.linkText("Selenium Scripts")).click();

    }

      Double click :- 

    @Test
    public void Doubleclick() throws Exception {
    driver.get("http://techlearn.in/content/double-click");
    Thread.sleep(3000);
    Actions act = new Actions(driver);
    act.moveToElement
    (driver.findElement(By.xpath("//*[@id='node-235']/div/div[1]/div/div/button"))).doubleClick().perform();

    }

     Full page Screenshot :- 

    public class TechLearn {

    public WebDriver driver;
    public Selenium selenium;

    public void Screenshot() 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 machinepath
    //
    FileUtils.copyFile(f, new File("F:\\Workspace\\Techlearn"+time+".png")); // for windowsmatchine path

    }
    @Test // Print Full Screenshot
    public void PrintScreenShot() throws Exception{
    driver.get("http://techlearn.in");
    Screenshot();
    }

    Keyboard actions :- 

    driver.get("http://www.seleniumlearn.com");
    String selectalltext = Keys.chord(Keys.CONTROL, "a"); // select all text in techlearn.in home page
    driver.findElement(By.linkText("TechLearn.in")).sendKeys(selectalltext);
                             
                                                                        
                                                       {Or }

    driver.findElement(By.linkText("www.seleniumlearn.com")).sendKeys(Keys.CONTROL, "t");
    driver.navigate().to("http://in.linkedin.com/in/purushothamk"); 
    driver.findElement(By.linkText("Personal Website")).sendKeys(Keys.CONTROL, "n");
    Set<String> window1=driver.getWindowHandles();
    Object s[]=window1.toArray();
    driver.switchTo().window(s[1].toString());

    driver.get("http://www.seleniumlearn.com"); 

                                                                      

    @Test
          public void KeyboardactionNewPrivateWindow() throws AWTException {
              driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
              driver.get("http://techlearn.in/Register");

              Actions act=new Actions(driver);
              act.contextClick(driver.findElement(By.linkText("TechLearn.in"))).perform();  
    // Right click action

              driver.findElement(By.linkText("TechLearn.in")).sendKeys(Keys.ARROW_DOWN);  // Arrow down 3 times
              driver.findElement(By.linkText("TechLearn.in")).sendKeys(Keys.ARROW_DOWN);
              driver.findElement(By.linkText("TechLearn.in")).sendKeys(Keys.ARROW_DOWN);

              driver.findElement(By.linkText("TechLearn.in")).sendKeys(Keys.ENTER);  // Click on Enter button .
          } 
                                                                                                Click all Keyboard actions:-

     Robot class in Selenium :- 

     Robot rbt= new Robot();                        // Create object of Robot class
      rbt.keyPress(KeyEvent.VK_ENTER);      // Press Enter
      rbt.keyRelease(KeyEvent.VK_ENTER);  // Release Enter

                                                
     

      Handle SSL Certification in Firefox :- 

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

    driver= new FirefoxDriver(capabilities);
    driver.get("https://www.seleniumlearn.com/");
                                                                         
    Visit complete code:

      Handle SSL Certification in Google Chrome :- 

     DesiredCapabilities capabilities = DesiredCapabilities.chrome(); 
     capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); 

     System.setProperty("webdriver.chrome.driver", "/home/chinna/lib/chromedriver");// Your chromedriver path.
     driver = new ChromeDriver(capabilities); 
     driver.get("https://www.seleniumlearn.com"); 
                                                                            
    Visit complete code:

     Handle alert & Handle alert conformation :- 

    We have to navigateto Alert or Confirmation windows

    driver.switchTo().alert();                                                  

    To click on "OK"  or "Cancel" on Alertor Confirmation 

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

    driver.switchTo().alert().dismiss();—ToclickCancel  

    @Test
    public void Entertext()throws Exception {
    driver.get("http://www.techlearn.in/content/how-insert-text-text-field-model-window-...");
    Thread.sleep(5000);
    driver.findElement(By.xpath("//*[@id='node-223']/div/div[1]/div/div/button")).click();
    Alert alert = driver.switchTo().alert();
    alert.sendKeys("The value that you wish to enter");
    alert.accept();

    }                                                                                           

      Handle Popup :- 

    We have to navigate to the popup windows

    driver.switchTo().window(“WindowName”);

    To navigate from Popup window to main window

    driver.switchTo().window(“MainWindowName”);

    Below approach to handle Dynamically changing popup windows

    Set<String> window1= driver.getWindowHandles();
    Object s[]=window1.toArray();
    driver.switchTo().window(s[1].toString());

    Handle multiple popups windows

    driver.getWindowHandles();

      Sikuli :- 

    public class Gmail_Upload {
        public WebDriver driver;
        public Screen s;

    @Test // SIKULI SCRIPT for  upload file
    public void FileAttachement() throws Exception {
    driver.get("http://techlearn.in/Register");
    driver.findElement(By.id("edit-submitted-uploadfile-upload")).click();
    s.click("/home/chinna/lib/Sikuli/techlearn.in.png");        // (Or) s.click("Image")
    driver.findElement(By.id("edit-submitted-uploadfile-upload-button--4")).click();
    }
    @BeforeTest

     public void beforeTest() {
    driver=new FirefoxDriver();
     s=new Screen();
    }

      AutoIT :- 

    @Test
    public void FileAttachement() throws Exception {
    driver.manage().timeouts().implicitlyWait(9, TimeUnit.SECONDS);
    driver.get("http://techlearn.in/Register");
    driver.findElement(By.id("edit-submitted-uploadfile-upload")).click();

    Runtime.getRuntime().exec("C:\\Users\\chinna\\Desktop\\AutoIT\\Fileupload.exe");
    }
                                                                         

      Log4j  :- 
      public class Log4j {
      public static void main(String[] args) throws Exception {
      Logger logger= Logger.getLogger("LogLearning");
      PropertyConfigurator.configure("Log4j.properties");

      System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.Jdk14Logger");
      WebDriver driver= new FirefoxDriver();
      public WebDriver driver;
      logger.info("Firefox Opened");

      driver.manage().window().maximize();
      logger.info("Brows maximized");

      driver.get("http://www.techlearn.in");
      logger.info("Website is launched");
      } 
                                                        

      Capture window name :- 

    driver.getWindowHandle();

      Excel (xls) files :- 

     

      Number of frames on a page :- 

    List<WebElement>framesList=driver.findElements(By.xpath("//iframe"));
    intnumOfFrames=frameList.size();

      Print all COOKIES :- 

    @Test

    public void CookiesinWebsite() throws Exception
    {
    driver.get("http://www.techlearn.in");
    // Now set the cookie. This one's valid for the entire domain
    Cookie cookie = new Cookie("key", "value");
    driver.manage().addCookie(cookie);
    // And now output all the available cookies for the current URL
    Set<Cookie> allCookies = driver.manage().getCookies();
    for (Cookie loadedCookie : allCookies) {
    System.out.println(String.format("%s -> %s", loadedCookie.getName(), loadedCookie.getValue()));
    }
    }

      Scroll Up & Down :- 

     How to scroll to bottom/down of page in Selenium ?

    @Test //(enabled=false)
    public void ScrolltoBottomonPage() throws Exception
    {
    driver.get("http://www.techlearn.in");
    Thread.sleep(5000);
    ((JavascriptExecutor) driver).executeScript("window.scrollBy(0,5000)");

    // OR

    JavascriptExecutor jse = (JavascriptExecutor)driver;
    jse.executeScript("window.scrollBy(0,1000)", "");

    // OR

    jse.executeScript("scroll(0, 250)");

    }

    @Test //Page Scroll "DOWN" using Selenium WebDriver
    public void ScrollDown() throws Exception {
    driver.get("http://www.seleniumlearn.com/");
    JavascriptExecutor jse = (JavascriptExecutor)driver;
    jse.executeScript("scroll(0, 950)"); // Y value is scroll down
    Thread.sleep(5000);
    }
    @Test //Page Scroll "UP" using Selenium WebDriver
    public void ScrollTop() throws Exception {
    driver.get("http://www.seleniumlearn.com/");
    Thread.sleep(3000);
    JavascriptExecutor jse = (JavascriptExecutor)driver;
    jse.executeScript("scroll(750, 0)"); // X value is scroll up
    }

     Number of links on a page :- 

    @Test
    public void TotalLinks() throws Exception
    {
    driver.get("http://www.seleniumlearn.com/");
    List<WebElement> alllinks=driver.findElements(By.tagName("a"));
    System.out.println("Total No of links on techlearn.in webpage :" +alllinks.size());
    }

                                                          

     Print all links names on a page :- 
        @Test 
        public void DisplayAllLinksNames() {
        driver.get("http://techlearn.in/");
        List<WebElement> alllinks= driver.findElements(By.tagName("a"));
        for(WebElement link:alllinks)
        System.out.println(link.getText());

        }

                                                          

     Print all links on a website :- 

        public class PrintAllLinks {
        public WebDriver driver;
        private static String[] links = null;
        private static int linksCount = 0;
        @Test 
        public void DisplayAllLinksNames() throws Exception{
        driver.manage().timeouts().implicitlyWait(9,TimeUnit.SECONDS);
        driver.get("http://www.seleniumlearn.com/");
        List<WebElement> alllinks = driver.findElements(By.tagName("a")); 
        linksCount = alllinks.size();
        links= new String[linksCount];
        System.out.println("Print All links on a web page :");
        for(int i=0;i<linksCount;i++)
        {
        links[i] = alllinks.get(i).getAttribute("href");
        System.out.println(alllinks.get(i).getAttribute("href"));
        }
        
                                                                        

     Visit all links on a page :- 
    driver.get("http://www.techlearn.in");
    List<WebElement> all_links_webpage = driver.findElements(By.tagName("a")); 
    System.out.println("Print total no of links");
    linksCount = all_links_webpage.size();
    System.out.println(linksCount); 
    links= new String[linksCount];
    System.out.println("Print Links");
    for(int i=0;i<linksCount;i++)
    {
    links[i] = all_links_webpage.get(i).getAttribute("href");
    System.out.println(all_links_webpage.get(i).getAttribute("href"));
    }
    homeWindow = driver.getWindowHandle().toString(); 
    System.out.println("Visiting Each Link"); 
    for(int i=0;i<linksCount;i++)
    {
    driver.navigate().to(links[i]);
    Thread.sleep(3000);
    driver.switchTo().window(homeWindow);
    }
                                                  

      Broken Links :- 

    public class Broken {
    public static void main(String[] args) throws Exception {
    WebDriver driver=new FirefoxDriver();
    driver.get("http://archives.peoplesdemocracy.in/");
    List<WebElement> ele=driver.findElements(By.tagName("a"));
    for(int i=0;i<ele.size();i++) {
    int statusCode=0;
    try{
    statusCode=getResponseCode(ele.get(i).getAttribute("href"));
    }catch(Exception e)
    {
    e.printStackTrace();
    }
    if(statusCode==404) {
    System.out.println("INVALIDLINKS :-> "+ele.get(i).getAttribute("href"));
    }
    }
    }
    public static int getResponseCode(String urlString) throws IOException{
    URL u = new URL(urlString);
    HttpURLConnection h = (HttpURLConnection) u.openConnection();
    h.setRequestMethod("GET");
    h.connect();
    return h.getResponseCode();
    }
    }                                                            

      Browser name & version/Platform OS Name & version :- 

    @Test
    public void printBrowerNameandVersionNameandOSName2() throws Exception {

    String s = (String) ((JavascriptExecutor) driver).executeScript("return navigator.userAgent;");
    System.out.println("Browser name : " + s);
    }

                 Visit complete code 1:                  Visit complete code  2:

     Handle Auto suggestion:- 

    @Test
            public void AjaxExample() throws Exception {
            driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
            driver.get("http://www.google.com");
            driver.findElement(By.name("q")).sendKeys("selenium");
            Thread.sleep(3000);
            driver.findElement(By.name("q")).sendKeys(Keys.ARROW_DOWN);
            driver.findElement(By.name("q")).sendKeys(Keys.ARROW_DOWN);
            driver.findElement(By.name("q")).sendKeys(Keys.ARROW_DOWN);
            driver.findElement(By.name("q")).sendKeys(Keys.ENTER);
            }

                                                          Example :-

     

     Get all option list in dropdown  :- 

    @Test
    public void GetAllOptionsList() throws Exception {
    driver.get("http://techlearn.in/Register");
    Thread.sleep(3000);
    List<WebElement> allCities=new Select(driver.findElement(By.id("edit-submitted-country"))).getOptions();
    for(WebElement city:allCities)
    {
    System.out.println(city.getText());
    }

    }                                                                              
    Visit complete code

      Responsive size (Mobile/Tablet/Laptop/Desktop) :- 

    @Test
    public void BrowserwithGivenDimension() throws Exception
    {
    driver.get("http://techlearn.in");
    driver.manage().window().maximize();//The standard layout is for desktops, laptops and other large screen devices.
    System.out.println(driver.manage().window().getSize());
    Thread.sleep(5000);
    driver.get("http://techlearn.in");
    Dimension n = new Dimension(580,768); //Tablet devicessuch as iPad, Android and Windows tablets have two orientations
    driver.manage().window().setSize(n);
    System.out.println(driver.manage().window().getSize());
    Thread.sleep(5000);
    driver.get("http://techlearn.in");
    Dimension k = new Dimension(320,580); //Smalltouch devicessuch as iPhone, Android and Windows phones
    driver.manage().window().setSize(k);
    System.out.println(driver.manage().window().getSize());
    }                                                                                                        

                                                               Visit complete code

     ExtJS Combo Boxes       :- 

    @Test
    public void ExtJsCombo() throws Exception
    {
    driver.get("http://www.naukri.com/");
    WebElement Category=driver.findElement(By.id("farea"));
    Category.click();
    WebElement CategoryItems=driver.findElement(By.id("fareaSL"));
    Select Sel= new Select(CategoryItems);
    List<WebElement> ListItems=Sel.getOptions();
    for(int i=1;i<=ListItems.size()-1;i++)
    {
    System.out.println(ListItems.get(i).getText());
    }
    }

      Image width and Height :- 

    @Test
    public void WidthndHight() throws Exception {
    driver.get("http://techlearn.in");
    driver.findElement(By.linkText("About Us")).click();
    Thread.sleep(3000);
    Dimension dimesions=driver.findElement(By.className("image-style-none")).getSize();
    System.out.println("Width : "+ dimesions.width); //Print the Width of the Image
    System.out.println("Height : "+ dimesions.height); //Print the Height of the Image
    }                
                                                          
    Visit complete code

      Web page Load time :- 

    @Test // Description = Checking the Web Page load time using Selenium WebDriver
    public void LoadTime(){
    long startTime = System.currentTimeMillis()/1000;
    System.out.println("The startTime is "+startTime);
    //Set the acceptable Page load time to 60 sec
    driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
    driver.get("http://www.techlearn.in/");
    WebElement search = driver.findElement(By.id("edit-search-block-form--2"));
    //Iterate through the loop as long as time(60sec) is with in the acceptable Page load time
    while(((System.currentTimeMillis()/1000)-startTime)<60){
    if(search.isDisplayed()){
    long endTime = System.currentTimeMillis()/1000;
    System.out.println("The endTime is "+endTime);
    long loadTime = endTime - startTime;
    System.out.println("Totaltime: " +loadTime + " seconds");
    break;
    }
    }
    }                                              
    Visit complete code 1:                      Visit complete code 2: 

            :- 

    32) How to handle conformation prompt dialog box using selenium webdriver ?

    @Test
    public void ConformationAlertBox()throws Exception {
    driver.get("http://techlearn.in/content/how-handle-confirmation-popup-selenium-webdr...");
    Thread.sleep(2000);
    driver.findElement(By.xpath("//*[@id='node-221']/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
    }

     

     

      File upload :- 

    @Test
    public void Uploadfile() throws Exception {
    driver.get("http://techlearn.in/content/upload-file-and-submit-functionality");
    Thread.sleep(7000);
    driver.findElement(By.name("pic")).sendKeys("/home/chinna/Desktop/chna.jpg"); // Add your file path
    driver.findElement(By.xpath("//*[@id='node-226']/div/div[1]/div/div/form/input[2]")).click();
    }                                        

                                                                                Visit complete code                                                

      File Download :-
    @BeforeMethod
            private void openBrowser(){
            try{
            FirefoxProfile fxProfile = new FirefoxProfile();
            fxProfile.setPreference("browser.download.folderList",2);
            fxProfile.setPreference("browser.download.manager.showWhenStarting",false);
            fxProfile.setPreference("browser.download.dir","/home/chinna/Desktop/Locust/pdf"); // ADD YOUR DOWNLOAD PATH
            fxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/pdf");
            fxProfile.setPreference("browser.download.manager.showWhenStarting", false);
            fxProfile.setPreference("browser.download.manager.focusWhenStarting", false);
            fxProfile.setPreference("browser.helperApps.alwaysAsk.force", false);
            fxProfile.setPreference("browser.download.manager.alertOnEXEOpen", false);
            fxProfile.setPreference("browser.download.manager.closeWhenDone", false);
            fxProfile.setPreference("browser.download.manager.showAlertOnComplete", false);
            fxProfile.setPreference("browser.download.manager.useWindow", false);
            fxProfile.setPreference("browser.download.manager.showWhenStarting",false);
            fxProfile.setPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", false);
            fxProfile.setPreference( "pdfjs.disabled", true );
            driver = new FirefoxDriver(fxProfile);
            driver.manage().timeouts().implicitlyWait(15,TimeUnit.SECONDS);
            driver.manage().window().maximize();
            driver.get("http://techlearn.in/content/selenium-2-experiance");
            Thread.sleep(2000);
            waitForTitleToPresent("Selenium 2+ Experiance | TechLearn");
            }catch(Throwable t){
            System.err.println("There is an issue in launching the application ,please check "+t); 
            }        }
            private void waitForTitleToPresent(String locator){
            WebDriverWait wait=new WebDriverWait(driver,15);
            wait.until(ExpectedConditions.titleIs(locator));
            }
    @Test
            public void PDFDOWNLOAD() throws InterruptedException{
            Thread.sleep(1000);
            driver.switchTo().frame(driver.findElement(By.className("pdf")));
            driver.findElement(By.id("download")).click();
            Thread.sleep(5000);        } 

                                                       Example:

     Web page Load time :- 

    @Test
    public void WebPageLoadTest() {
    long start = System.currentTimeMillis();

    driver.get("http://www.techlearn.in");

    long finish = System.currentTimeMillis();
    long totalTime = finish - start;
    System.out.println("Total Time for page load - "+totalTime);

    }

                                                  Example:

     

     Get list of all checkboxes :- 

    @Test
    public void GetAllCheckboxlist()throws Exception {
    driver.get("http://techlearn.in/Register");
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    List<WebElement> s=driver.findElements(By.id("edit-submitted-country"));
    System.out.println(s.size());
    for (int i = 0; i < s.size(); i++) {
    System.out.println(s.get(i).getText());
    }
    }

                                                                          Example:

      New tab in the same browser :- 

    @Test
    public void Newtab() throws Exception {
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.get("http://techlearn.in");
    {
    driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t");
    ArrayList<String> tabs = new ArrayList<String> (driver.getWindowHandles());
    driver.switchTo().window(tabs.get(0));
    driver.get("http://facebook.com/chinna.in");
    }
    }        
                                                                                        Example :

     Web page Zoom IN and Zoom OUT :- 

    @Test
      public void BrowserZoomIN() {
       zoomIn();  
       }
      public void zoomIn()  {
      for(int i=0; i<5; i++){   
      driver.findElement(By.linkText("TechLearn.in")).sendKeys(Keys.CONTROL, Keys.ADD);
       }                

     

     

     

    Alert handling in selenium webdriver :-

    public void checkAlert() {
        try {
            WebDriverWait wait = new WebDriverWait(driver, 5);
            wait.until(ExpectedConditions.alertIsPresent());
            Alert alert = driver.switchTo().alert();
            alert.accept();
        } catch (Exception e) {       //exception handling
        }
    }

     

    S.No Command Description
    1 addLocationStrategy  
    2 addLocationStrategyAndWait  
    3 addScript  
    4 addScriptAndWait  
    5 addSelection  
    6 addSelectionAndWait  
    7 allowNativeXpath  
    8 allowNativeXpathAndWait  
    9 altKeyDown  
    10 altKeyDownAndWait  
    11 altKeyUp  
    12 altKeyUpAndWait  
    13 answerOnNextPrompt  
    14 assertAlert  
    15 assertAlertNotPresent  
    16 assertAlertPresent  
    17 assertAllButtons  
    18 assertAllFields  
    19 assertAllLinks  
    20 assertAllWindowIds  
    21 assertAllWindowNames  
    22 assertAllWindowTitles  
    23 assertAttribute  
    24 assertAttributeFromAllWindows  
    25 assertBodyText  
    26 assertChecked  
    27 assertConfirmation  
    28 assertConfirmationNotPresent  
    29 assertConfirmationPresent  
    30 assertCookie  
    31 assertCookieByName  
    32 assertCookieNotPresent  
    33 assertCookiePresent  
    34 assertCursorPosition  
    35 assertEditable  
    36 assertElementHeight  
    37 assertElementIndex  
    39 assertElementPositionLeft  
    40 assertElementPositionTop  
    41 assertElementPresent  
    42 assertElementWidth  
    43 assertEval  
    44 assertExpression  
    45 assertHtmlSource  
    46 assertLocation  
    47 assertMouseSpeed  
    48 assertNotAlert  
    49 assertNotAllButtons  
    50 assertNotAllFields  
    51 assertNotAllLinks  
    52 assertNotAllWindowIds  
    53 assertNotAllWindowNames  
    54 assertNotAllWindowTitles  
    55 assertNotAttribute  
    56 assertNotAttributeFromAllWindows  
    57 assertNotBodyText  
    58 assertNotChecked  
    59 assertNotConfirmation  
    60 assertNotCookie  
    61 assertNotCookieByName  
    62 assertNotCursorPosition  
    63 assertNotEditable  
    64 assertNotElementHeight  
    65 assertNotElementIndex  
    66 assertNotElementPositionLeft  
    67 assertNotElementPositionTop  
    68 assertNotElementWidth  
    69 assertNotEval  
    70 assertNotExpression  
    71 assertNotHtmlSource  
    72 assertNotLocation  
    73 assertNotMouseSpeed  
    74 assertNotOrdered  
    75 assertNotPrompt  
    76 assertNotSelectOptions  
    77 assertNotSelectedId  
    78 assertNotSelectedIds  
    79 assertNotSelectedIndex  
    80 assertNotSelectedIndexes  
    81 assertNotSelectedLabel  
    82 assertNotSelectedLabels  
    83 assertNotSelectedValue  
    84 assertNotSelectedValues  
    85 assertNotSomethingSelected  
    86 assertNotSpeed  
    87 assertNotTable  
    88 assertNotText  
    89 assertNotTitle  
    90 assertNotValue  
    91 assertNotVisible  
    92 assertNotWhetherThisFrameMatchFrameExpression  
    93 assertNotWhetherThisWindowMatchWindowExpression  
    94 assertNotXpathCount  
    95 assertOrdered  
    96 assertPrompt  
    97 assertPromptNotPresent  
    98 assertPromptPresent  
    99 assertSelectOptions  
    100 assertSelectedId  
    101 assertSelectedIds  
    102 assertSelectedIndex  
    103 assertSelectedIndexes  
    104 assertSelectedLabel  
    105 assertSelectedLabels  
    106 assertSelectedValue  
    107 assertSelectedValues  
    108 assertSomethingSelected  
    109 assertSpeed  
    110 assertTable  
    111 assertText  
    112 assertTextNotPresent  
    113 assertTextPresent  
    114 assertTitle  
    115 assertValue  
    116 assertVisible  
    117 assertWhetherThisFrameMatchFrameExpression  
    118 assertWhetherThisWindowMatchWindowExpression  
    119 assertXpathCount  
    120 assignId  
    121 assignIdAndWait  
    122 break  
    123 captureEntirePageScreenshot  
    124 captureEntirePageScreenshotAndWait  
    125 check  
    126 checkAndWait  
    127 chooseCancelOnNextConfirmation  
    128 chooseOkOnNextConfirmation  
    129 chooseOkOnNextConfirmationAndWait  
    130 click  
    131 clickAndWait  
    132 clickAt  
    133 clickAtAndWait  
    134 close  
    135 contextMenu  
    136 contextMenuAndWait  
    137 contextMenuAt  
    138 contextMenuAtAndWait  
    139 controlKeyDown  
    140 controlKeyDownAndWait  
    141 controlKeyUp  
    142 controlKeyUpAndWait  
    143 createCookie  
    144 createCookieAndWait  
    145 deleteAllVisibleCookies  
    146 deleteAllVisibleCookiesAndWait  
    147 deleteCookie  
    148 deleteCookieAndWait  
    149 deselectPopUp  
    150 deselectPopUpAndWait  
    151 doubleClick  
    152 doubleClickAndWait  
    153 doubleClickAt  
    154 doubleClickAtAndWait  
    155 dragAndDrop  
    156 dragAndDropAndWait  
    157 dragAndDropToObject  
    158 dragAndDropToObjectAndWait  
    159 dragdrop  
    160 dragdropAndWait  
    161 echo  
    162 fireEvent  
    163 fireEventAndWait  
    164 focus  
    165 focusAndWait  
    166 goBack  
    167 goBackAndWait  
    168 highlight  
    169 highlightAndWait  
    170 ignoreAttributesWithoutValue  
    171 ignoreAttributesWithoutValueAndWait  
    172 keyDown  
    173 keyDownAndWait  
    174 keyPress  
    175 keyPressAndWait  
    176 keyUp  
    177 keyUpAndWait  
    178 metaKeyDown  
    179 metaKeyDownAndWait  
    180 metaKeyUp  
    181 metaKeyUpAndWait  
    182 mouseDown  
    183 mouseDownAndWait  
    184 mouseDownAt  
    185 mouseDownAtAndWait  
    186 mouseDownRight  
    187 mouseDownRightAndWait  
    188 mouseDownRightAt  
    189 mouseDownRightAtAndWait  
    190 mouseMove  
    191 mouseMoveAndWait  
    192 mouseMoveAt  
    193 mouseMoveAtAndWait  
    194 mouseOut  
    195 mouseOutAndWait  
    196 mouseOver  
    197 mouseOverAndWait  
    198 mouseUp  
    199 mouseUpAndWait  
    200 mouseUpAt  
    201 mouseUpAtAndWait  
    202 mouseUpRight  
    203 mouseUpRightAndWait  
    204 mouseUpRightAt  
    205 mouseUpRightAtAndWait  
    206 open  
    207 openWindow  
    208 openWindowAndWait  
    209 pause  
    210 refresh  
    211 refreshAndWait  
    212 removeAllSelections  
    213 removeAllSelectionsAndWait  
    214 removeScript  
    215 removeScriptAndWait  
    216 removeSelection  
    217 removeSelectionAndWait  
    218 rollup  
    219 rollupAndWait  
    220 runScript  
    221 runScriptAndWait  
    222 select  
    223 selectAndWait  
    224 selectFrame  
    225 selectPopUp  
    226 selectPopUpAndWait  
    227 selectWindow  
    228 sendKeys  
    229 setBrowserLogLevel  
    230 setBrowserLogLevelAndWait  
    231 setCursorPosition  
    232 setCursorPositionAndWait  
    233 setMouseSpeed  
    234 setMouseSpeedAndWait  
    235 setSpeed  
    236 setSpeedAndWait  
    237 setTimeout  
    238 shiftKeyDown  
    239 shiftKeyDownAndWait  
    240 shiftKeyUp  
    241 shiftKeyUpAndWait  
    242 store  
    243 storeAlert  
    244 storeAlertPresent  
    245 storeAllButtons  
    246 storeAllFields  
    247 storeAllLinks  
    248 storeAllWindowIds  
    249 storeAllWindowNames  
    250 storeAllWindowTitles  
    251 storeAttribute  
    252 storeAttributeFromAllWindows  
    253 storeBodyText  
    254 storeChecked  
    255 storeConfirmation  
    256 storeConfirmationPresent  
    257 storeCookie  
    258 storeCookieByName  
    259 storeCookiePresent  
    260 storeCursorPosition  
    261 storeEditable  
    262 storeElementHeight  
    263 storeElementIndex  
    264 storeElementPositionLeft  
    265 storeElementPositionTop  
    266 storeElementPresent  
    267 storeElementWidth  
    268 storeEval  
    269 storeExpression  
    270 storeHtmlSource  
    271 storeLocation  
    272 storeMouseSpeed  
    273 storeOrdered  
    274 storePrompt  
    275 storePromptPresent  
    276 storeSelectOptions  
    277 storeSelectedId  
    278 storeSelectedIds  
    279 storeSelectedIndex  
    280 storeSelectedIndexes  
    281 storeSelectedLabel  
    282 storeSelectedLabels  
    283 storeSelectedValue  
    284 storeSelectedValues  
    285 storeSomethingSelected  
    286 storeSpeed  
    287 storeTable  
    288 storeText  
    289 storeTextPresent  
    290 storeTitle  
    291 storeValue  
    292 storeVisible  
    293 storeWhetherThisFrameMatchFrameExpression  
    294 storeWhetherThisWindowMatchWindowExpression  
    295 storeXpathCount  
    296 submit  
    297 submitAndWait  
    298 type  
    299 typeAndWait  
    300 typeKeys  
    301 typeKeysAndWait  
    302 uncheck  
    303  uncheckAndWait  
    304 useXpathLibrary  
    305 useXpathLibraryAndWait  
    306 verifyAlert  
    307 verifyAlertNotPresent  
    308 verifyAlertPresent  
    309 verifyAllButtons  
    310 verifyAllFields  
    311 verifyAllLinks  
    312 verifyAllWindowIds  
    313 verifyAllWindowNames  
    314 verifyAllWindowTitles  
    315 verifyAttribute  
    316 verifyAttributeFromAllWindows  
    317 verifyBodyText  
    318 verifyChecked  
    319 verifyConfirmation  
    320 verifyConfirmationNotPresent  
    321 verifyConfirmationPresent  
    322 verifyCookie  
    323 verifyCookieByName  
    324 verifyCookieNotPresent  
    325 verifyCookiePresent  
    326 verifyCursorPosition  
    327 verifyEditable  
    328 verifyElementHeight  
    329 verifyElementIndex  
    330 verifyElementNotPresent  
    331 verifyElementPositionLeft  
    332 verifyElementPositionTop  
    333 verifyElementPresent  
    334 verifyElementWidth  
    335 verifyEval  
    336 verifyExpression  
    337 verifyHtmlSource  
    338 verifyLocation  
    339 verifyMouseSpeed  
    340 verifyNotAlert  
    341 verifyNotAllButtons  
    342 verifyNotAllFields  
    343 verifyNotAllLinks  
    344 verifyNotAllWindowIds  
    345 verifyNotAllWindowNames  
    346 verifyNotAllWindowTitles  
    347 verifyNotAttribute  
    348 verifyNotAttributeFromAllWindows  
    349 verifyNotBodyText  
    350 verifyNotChecked  
    351 verifyNotConfirmation  
    352 verifyNotCookie  
    353 verifyNotCookieByName  
    354 verifyNotCursorPosition  
    355 verifyNotEditable  
    356 verifyNotElementHeight  
    357 verifyNotElementIndex  
    358 verifyNotElementPositionLeft  
    359 verifyNotElementPositionTop  
    360 verifyNotElementWidth  
    361 verifyNotEval  
    362 verifyNotExpression  
    363 verifyNotHtmlSource  
    364 verifyNotLocation  
    365 verifyNotMouseSpeed  
    366 verifyNotOrdered  
    367 verifyNotPrompt  
    368 verifyNotSelectOptions  
    369 verifyNotSelectedId  
    370 verifyNotSelectedIds  
    371 verifyNotSelectedIndex  
    372 verifyNotSelectedIndexes  
    373 verifyNotSelectedLabel  
    374 verifyNotSelectedLabels  
    375 verifyNotSelectedValue  
    376 verifyNotSelectedValues  
    377 verifyNotSomethingSelected  
    378 verifyNotSpeed  
    379 verifyNotTable  
    380 verifyNotText  
    381 verifyNotTitle  
    382 verifyNotValue  
    383 verifyNotVisible  
    384 verifyNotWhetherThisFrameMatchFrameExpression  
    385 verifyNotWhetherThisWindowMatchWindowExpression  
    386 verifyNotXpathCount  
    387 verifyOrdered  
    388 verifyPrompt  
    389 verifyPromptNotPresent  
    390 verifyPromptPresent  
    391 verifySelectOptions  
    392 verifySelectedId  
    393 verifySelectedIds  
    394 verifySelectedIndex  
    395 verifySelectedLabel  
    396 verifySelectedLabels  
    397 verifySelectedValue  
    398 verifySelectedValues  
    399 verifySomethingSelected  
    400 verifySpeed  
    401 verifyTable  
    402 verifyText  
    403 verifyTextNotPresent  
    404 verifyTextPresent  
    405 verifyTitle  
    406 verifyValue  
    407 verifyVisible  
    408 verifyWhetherThisFrameMatchFrameExpression  
    409 verifyWhetherThisWindowMatchWindowExpression  
    410 verifyXpathCount  
    411 waitForAlert  
    412 waitForAlertNotPresent  
    413 waitForAlertPresent  
    414 waitForAllButtons  
    415 waitForAllFields  
    416 waitForAllLinks  
    417 waitForAllWindowIds  
    418 waitForAllWindowNames  
    419 waitForAllWindowTitles  
    420 waitForAttribute  
    421 waitForAttributeFromAllWindows  
    422 waitForBodyText  
    423 waitForChecked  
    424 waitForCondition  
    425 waitForConfirmation  
    426 waitForConfirmationNotPresent  
    427 waitForConfirmationPresent  
    428 waitForCookie  
    429 waitForCookieByName  
    430 waitForCookieNotPresent  
    431 waitForCookiePresent  
    432 waitForCursorPosition  
    433 waitForEditable  
    434 waitForElementHeight  
    435 waitForElementIndex  
    436 waitForElementNotPresent  
    437 waitForElementPositionLeft  
    438 waitForElementPositionTop  
    439 waitForElementPresent  
    440 waitForElementWidth  
    441 waitForEval  
    442 waitForExpression  
    443 waitForFrameToLoad  
    444 waitForHtmlSource  
    445 waitForLocation  
    446 waitForMouseSpeed  
    447 waitForNotAlert  
    448 waitForNotAllButtons  
    449 waitForNotAllFields  
    450 waitForNotAllLinks  
    451 waitForNotAllWindowIds  
    452 waitForNotAllWindowNames  
    453 waitForNotAllWindowTitles  
    454 waitForNotAttribute  
    455 waitForNotAttributeFromAllWindows  
    456 waitForNotBodyText  
    457 waitForNotChecked  
    458 waitForNotConfirmation  
    459 waitForNotCookie  
    460 waitForNotCookieByName  
    461 waitForNotCursorPosition  
    462 waitForNotEditable  
    463 waitForNotElementHeight  
    464 waitForNotElementIndex  
    465 waitForNotElementPositionLeft  
    466 waitForNotElementPositionTop  
    467 waitForNotElementWidth  
    468 waitForNotEval  
    469 waitForNotExpression  
    470 waitForNotHtmlSource  
    471 waitForNotLocation  
    472 waitForNotMouseSpeed  
    473 waitForNotOrdered  
    474 waitForNotPrompt  
    475 waitForNotSelectOptions  
    476 waitForNotSelectedId  
    477 waitForNotSelectedIds  
    478 waitForNotSelectedIndex  
    479 waitForNotSelectedIndexes  
    480 waitForNotSelectedLabel  
    481 waitForNotSelectedLabels  
    482 waitForNotSelectedValue  
    483 waitForNotSelectedValues  
    484 waitForNotSomethingSelected  
    485 waitForNotSpeed  
    486 waitForNotTable  
    487 waitForNotText  
    488 waitForNotTitle  
    489 waitForNotValue  
    490 waitForNotVisible  
    491 waitForNotWhetherThisFrameMatchFrameExpression  
    492 waitForNotWhetherThisWindowMatchWindowExpression  
    493 waitForNotXpathCount  
    494 waitForOrdered  
    495 waitForPageToLoad  
    496 waitForPopUp  
    497 waitForPrompt  
    498 waitForPromptNotPresent  
    499 waitForPromptPresent  
    500 waitForSelectOptions  
    501 waitForSelectedId  
    502 waitForSelectedIds  
    503 waitForSelectedIndex  
    504 waitForSelectedIndexes  
    505 waitForSelectedLabel  
    506 waitForSelectedLabels  
    507 waitForSelectedValue  
    508 waitForSelectedValues  
    509 waitForSomethingSelected  
    510 waitForSpeed  
    511 waitForTable  
    512 waitForText  
    513 waitForTextNotPresent  
    514 waitForTextPresent  
    515 waitForTitle  
    516 waitForValue  
    517 waitForVisible  
    518 waitForWhetherThisFrameMatchFrameExpression  
    519 waitForWhetherThisWindowMatchWindowExpression  
    520 waitForXpathCount  
    521 windowFocus  
    522 windowFocusAndWait  
    523 windowMaximize  
    524 windowMaximizeAndWait  
     

     

     

     

     

     

     

    Comments