Search On Google

Showing posts with label SELENIUM. Show all posts
Showing posts with label SELENIUM. Show all posts

Tuesday, February 19, 2019

Selenium multiple popup handling

How to handle popup in selenium?
In popup handling we switch on alert box by using switchTo() with alert() on driver object.
Example:-         Alert alert2 = driver.switchTo().alert();
and if you want to get alert text then use getText() on alert object.
 Example: -       String text2 =alert3.getText();


There are 3 type of alert in webpages.
1.simple alert.
2.confirmation alert
3.Text box alert

1.Simple alert box js code example:-
Here inbuilt alert method used for popup.
"function simpleAlert()
{
alert('ok')
}"

2.Confirmation alert js code example:-
Here inbuilt confirm method used.
"function confirmation(){
if (confirm(""Press a button!"")) {
  txt = ""You pressed OK!"";
} else {
  txt = ""You pressed Cancel!"";
}
}"

3.Text box alert js code example:- 
In this we use prompt method of windows.
"
function myFunction() {
  var txt;
  var person = prompt(""Please enter your website:"", ""www.onlinetutorial.info"");
  if (person == null || person == """") {
    txt = ""User cancelled the prompt."";
  } else {
    txt = ""Hello "" + person + ""! How are you today?"";
  }
  document.getElementById(""demo"").innerHTML = txt;
}"

Example of popup handling in selenium with complete java code:-

"package pkg1;

import org.openqa.selenium.Alert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class MyClass913_popup_handling { 
    public static void main(String[] args) {       
   
        System.setProperty(""webdriver.chrome.driver"",""C:\\Users\\Desk-105\\Documents\\SELENIUM\\chromedriver.exe"");   
        WebDriver driver = new ChromeDriver();   

        driver.get("https://www.onlinetutorial.info/p/selenium-popup-handling.html");

        /**
         * simple alert
         */
        WebElement element = driver.findElement(By.id(""textbox_1""));
        element.sendKeys(""pradeep yadav"");
        WebElement element2 = driver.findElement(By.id(""button_submit""));
        element2.click();
        Alert alert = driver.switchTo().alert();
     
     
        try {
   Thread.sleep(5000);
  } catch (InterruptedException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
     
     
        alert.accept();
     
        /**
         * confirmation alert popup
         */
     
        WebElement element3 = driver.findElement(By.id(""button_submit2""));
        element3.click();
     
        Alert alert2 = driver.switchTo().alert();
        String text =alert2.getText();
        System.out.println(text);
     
        try {
        Thread.sleep(5000);
       } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
       }
           
        alert2.accept();
     
        /**
         * text box popup
         */
     
        WebElement element4 = driver.findElement(By.id(""button_submit3""));
        element4.click();
     
        Alert alert3 = driver.switchTo().alert();
        String text2 =alert3.getText();
        System.out.println(text2);
     
        try {
        Thread.sleep(5000);
       } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
       }
           
        alert3.accept();
     
     
     
     
//        driver.close();
    }
}
"

Selenium multiple window handling

How to handle multiple window in browser with selenium?

For handling multiple window you have to follow some rules as given below.

String MainWindow=driver.getWindowHandle(); //gives parent window ID only

Set allwindowList = driver.getWindowHandles() //gives a set of windows ID

You should check ID with parent ID by looping over ID and do work as you wish at any page you want.

How to switch window:-
driver.switchTo().window(handle);
For switching window in selenium we use above code.

Program for switching and doing some tast on different window in selenium:-

"package pkg1;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class MyClass913_multiple_window_handling { 
    public static void main(String[] args) {       
   
        System.setProperty(""webdriver.chrome.driver"",""C:\\Users\\Desk-105\\Documents\\SELENIUM\\chromedriver.exe"");   
        WebDriver driver = new ChromeDriver();   

        /**
     * Open multiple windows.
   */
     
         String pageUrl = ""http://www.google.com"";
   driver.get(pageUrl);
    JavascriptExecutor jsExecutor = (JavascriptExecutor)driver;
    String jsOpenNewWindow = ""window.open('""+pageUrl+""');"";

    for(int i=0;i<6;i++)
    {
     jsExecutor.executeScript(jsOpenNewWindow);
     try {
    Thread.sleep(1000);
   } catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
     System.out.println((i+1)+"" opennd."");
    }
     
 
 
    /**
     * Handle multiple windows.
     */
         String MainWindow=driver.getWindowHandle();
         System.out.println(MainWindow);
         for( String window : driver.getWindowHandles()){
          System.out.println(window);
         }
       
         /**
          * window switching and closing new tabs
          */
         for(String handle : driver.getWindowHandles()) {
             if (!handle.equals(MainWindow)) {
              try {
      Thread.sleep(1000);
     } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
     }
                 driver.switchTo().window(handle);
                 driver.close();
             }
         }

       
     
    }
}
"

Selenium multiple tab handling

How to handle multiple tab in selenium?
We have two given method which excecute on driver
we can get current window object and other window object also by these method.
So if we have object for any tab then we can switch between them easily by code.

Example:-

String MainWindow=driver.getWindowHandle();

This code is useful for taking parent window ID.

Set allwindowList = driver.getWindowHandles()

This code give you all window ID list. By iterating above set you will get different window IDs.
You can iterate and switch at any time when required by following
switching code.

                driver.switchTo().window(childwindowID);

Exampe for switching tabs with selenium java code:-

"package pkg1;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class MyClass912_multiple_tab_handling { 
    public static void main(String[] args) {       
   
        System.setProperty(""webdriver.chrome.driver"",""C:\\Users\\Desk-105\\Documents\\SELENIUM\\chromedriver.exe"");   
        WebDriver driver = new ChromeDriver();   

        driver.get("https://www.onlinetutorial.info/p/selenium-tab-handling.html");
     
     
        String MainWindow=driver.getWindowHandle();
     
     WebElement element =driver.findElement(By.linkText(""Link-a""));
        element.click();

        WebElement element2 =driver.findElement(By.linkText(""Link-b""));
        element2.click();
     
        WebElement element3 =driver.findElement(By.linkText(""Link-c""));
        element3.click();
     
        WebElement element4 =driver.findElement(By.linkText(""Link-d""));
        element4.click();
     
        WebElement element5 =driver.findElement(By.linkText(""Link-e""));
        element5.click();
     
        WebElement element6 =driver.findElement(By.linkText(""Link-f""));
        element6.click();
     
        WebElement element7 =driver.findElement(By.linkText(""Link-g""));
        element7.click();
     
     
     
        /**
         * Tab switching
         */
        for(String handle : driver.getWindowHandles()) {
            if (!handle.equals(MainWindow)) {
             try {
     Thread.sleep(1000);
    } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
                driver.switchTo().window(handle);
                //driver.close();
            }
        }

        try {
   Thread.sleep(2000);
    driver.switchTo().window(MainWindow);
  } catch (InterruptedException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
     
        /**
         * Tab switching and closing new tabs
         */
        for(String handle : driver.getWindowHandles()) {
            if (!handle.equals(MainWindow)) {
             try {
     Thread.sleep(1000);
    } catch (InterruptedException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
                driver.switchTo().window(handle);
                driver.close();
            }
        }
     
     
    }
}
"

selenium upload file example

How to upload and download file by selenium?
For file upload with selenium you have to get id of select file elelement
and then you should sendKeys option to set file path .
That’s all to select file with selenium and then apply appropriate programming to send data to server
to upload your file.

Example to file selection:-
        myElement1.sendKeys("C:\\Users\\Desk-105\\Documents\\one.txt");

"package pkg1;

Example for upload file in selenium:-

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class MyClass911_upload_file { 
    public static void main(String[] args) {       
   
        System.setProperty(""webdriver.chrome.driver"",""C:\\Users\\Desk-105\\Documents\\SELENIUM\\chromedriver.exe"");   
        WebDriver driver = new ChromeDriver();   

        driver.get("https://www.onlinetutorial.info/p/selenium-upload-file.html");
        WebElement myElement1 =driver.findElement(By.id(""upload_file_1""));
        myElement1.sendKeys(""C:\\Users\\Desk-105\\Documents\\one.txt"");
        driver.findElement(By.id(""upload_file_button"")).click();
     
    }
}
"

Selenium mouse and keyboard event

Keyboard and mouse event?

clickAndHold()
Clicks (without releasing) at the current mouse location
contextClick()
Right click mouse action.
doubleClick()
Performs a double-click at the current mouse location.
dragAndDrop(source, target)
For drag drop action
dragAndDropBy(source, x-offset, y-offset)
here you can give offset of target for drag drop action.
keyDown(modifier_key)
This method perform to modifier key press. As we know modifier keys are ALT, SHIFT, CTRL
keyUp(modifier _key)
This method perform to modifier key release. As we know modifier keys are ALT, SHIFT, CTRL
moveToElement(toElement)
Moves the mouse to given element.
moveByOffset(x-offset, y-offset)
Moves the mouse to given offset.
release()
Release left pressed mouse button.
sendKeys(onElement, charsequence)
Sends  keystrokes onto the element.

Mouse and keyboard event example in selenium:-

"package pkg1;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;

public class MyClass910_mouse_event { 
    public static void main(String[] args) {       
   
        System.setProperty(""webdriver.chrome.driver"",""C:\\Users\\Desk-105\\Documents\\SELENIUM\\chromedriver.exe"");   
        WebDriver driver = new ChromeDriver();   

        driver.get("https://www.onlinetutorial.info/p/selenium-mouse-event.html");
        WebElement element1 =driver.findElement(By.linkText(""Link-a""));
        Actions builder = new Actions(driver);
        Action actionseries = builder.moveToElement(element1).click().build();
        //The build() method is always the final method used so that all the listed actions will be compiled into a single step.
         actionseries.perform();
       
       
         WebElement element2 =driver.findElement(By.linkText(""Link-b""));
         Action actionseries2 = builder.moveToElement(element2).click().build();
         //The build() method is always the final method used so that all the listed actions will be compiled into a single step.
          actionseries2.perform();
     
    }
}
"

Mouse and keyboard event with multiple actions example in selenium:-

"package pkg1;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;

public class MyClass910_mouse_event_Large { 
    public static void main(String[] args) {       
   
        System.setProperty(""webdriver.chrome.driver"",""C:\\Users\\Desk-105\\Documents\\SELENIUM\\chromedriver.exe"");   
        WebDriver driver = new ChromeDriver();   

        driver.get(""C:\\Users\\Desk-105\\Desktop\\mouse_event.html"");
     
        WebElement username =driver.findElement(By.id(""userID""));
     
        Actions builder = new Actions(driver);
        Action actionseries = builder.moveToElement(username)
                       .click()
                       .keyDown(username, Keys.SHIFT)
                       .sendKeys(""pradeep_yadav"")
                       .keyUp(username, Keys.SHIFT)
                       .doubleClick(username)
                       .contextClick()
                       .build();
               
                actionseries.perform();
       
       
 
     
    }
}
"

LinkText vs partialLinkText method

What is linkText?
Link text are text display for  a link . You can say a understandable form of link which can be user friendly.

What is partial link text?
Partial means some part of main link. You can under stand when you see example below.

<a href="www.google.com">Click here to download</a>

Link text example:- Click here to download
Partial linked text:-
 Click
Click here
here to
download
here to download
load
down

By example you can see partial link may be much more but linkText will be only one.

Java code example:-
By.linkText("click here")
By.partialLinkText("here")


JAVA code complete example you can execute this:-

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.chrome.ChromeDriver; 

public class LinkAndPartialLinkTextExample {   
     
    public static void main(String[] args) {       
        String baseUrl = ""www.onlinetutorial.info"";   
        System.setProperty(""webdriver.chrome.driver"",""C:\\chromedriver.exe"");   
        WebDriver driver = new ChromeDriver();   
         
        driver.get(baseUrl);   
        driver.findElement(By.partialLinkText(""down"")).click();
        //driver.findElement(By.linkText(""click here to download"")).click();   
       
        driver.quit(); 
    } 
}

Saturday, February 16, 2019

Selenium dropdown value select

How to select item in dropdown?

We know there are two type of select in HTML. Single select and multiple select.
We use Select class in java code to get Select object and use 3 possible methods to select items.
All 3 possible methods are given below.

1.select.selectByIndex(3)
2.selectByValue("valuexyz")
3.selectByVisibleText("xyz")

Example in java:-

" WebElement element2 =driver.findElement(By.id(""fruits""));
        Select fruits =new Select(element2);
        fruits.selectByIndex(6);
        fruits.selectByValue(""mango"");
        fruits.selectByVisibleText(""Kivi"");
        "


Complete Select dropdown example in java code:- Single and multiple select both


"package pkg1;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

public class MyClass9_selenium_dropdown { 
    public static void main(String[] args) {       
   
        System.setProperty(""webdriver.chrome.driver"",""C:\\Users\\Desk-105\\Documents\\SELENIUM\\chromedriver.exe"");   
        WebDriver driver = new ChromeDriver();   

        driver.get("https://www.onlinetutorial.info/p/selenium-dropdown-select.html");
     
        /**
         * single select example
         */
        WebElement element1 =driver.findElement(By.id(""gender""));
        Select genders =new Select(element1);
        genders.selectByVisibleText(""Other"");
     
     /**
      * multiple select example
      */
        WebElement element2 =driver.findElement(By.id(""fruits""));
        Select fruits =new Select(element2);
        fruits.selectByIndex(6);
        fruits.selectByValue(""mango"");
        fruits.selectByVisibleText(""Kivi"");
     
    }
}
"

Selenium click on href link and image

How to click on a href link by selenium webdriver?

We mostly use linkText and xpath locator for click on href link.
WebElement temp  =    driver.findElement(By.linkText("Click to me")).click();

How to click on image by selenium webdriver?

In image click we mostly use xpath and cssSelector locators.

WebElement temp = driver.findElement(By.xpath("//img[@src='demo1.jpeg']"));
WebElement temp = driver.findElement(By.cssSelector("a[src='demo2.jpeg']"));


Java code example for href click and image click


"package pkg1;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class MyClass8_Click_On_Image { 
    public static void main(String[] args) {       
   
        System.setProperty(""webdriver.chrome.driver"",""C:\\Users\\Desk-105\\Documents\\SELENIUM\\chromedriver.exe"");   
        WebDriver driver = new ChromeDriver();   

        driver.get("https://www.onlinetutorial.info/p/selenium-click-on-link-and-image.html");   
      /**
       * for click on image
       */
        WebElement element = driver.findElement(By.cssSelector(""img[src='a.jpg']""));
        element.click();
     
        /**
         * for click on href link
         */
        driver.findElement(By.linkText(""Click to me"")).click();
     
    }
}

Selenium findElement vs findElements

What is findElement?

Find element method is use to find single element by using any locators id, name etc

Webelement element= driver .findElement(By.id("id_1"));

What is findElements?

findElements is method is use to find multiple elements by using  locator  id, name ,Xpath  etc into a list.
This method mostly work with name and xpath locator because in some cases we have multiple element with same name.
In case of radio button multiple radio button use same name for grouping.

List<Webelement> elementsList1 = driver .findElements(By.id("radio_buttons"));
List<WebElement> elementsList2 =  driver.findElements(By.xpath("//div"));

JAVA Code Example for findElements:-


"package pkg1;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.*;

public class MyClass7_findElements_and_findElement { 
    public static void main(String[] args) {       
   
        System.setProperty(""webdriver.chrome.driver"",""C:\\chromedriver.exe"");   
        WebDriver driver = new ChromeDriver();   

        driver.get(""https://www.onlinetutorial.info/p/selenium-findelement-vs-findelements.html"");   
   
        List<WebElement> elements = driver.findElements(By.name(""name""));
        System.out.println(""Number of elements:"" +elements.size());

        for (int i=0; i<elements.size();i++){
          System.out.println(""Radio button text:"" + elements.get(i).getAttribute(""value""));
        }
    }
}

Selenium Web elements

What is forms in selenium?

Forms are webelement which have multiple elements like textbox, email, password, checkbox, radio button etc.

How to get access to any webelement for do some task on it?

We use locators for get access as below.
Suppose we have a text box with id name_1 then we use following code:-

Webelement element1= driver.findElement(By.id("name_1"))


How to set data in element  ?

element1.sendKeys("sandeep yadav");


How to reset data in field?

element1.clear()


Suppose we have button element then how to click on that element?

For clicking on element by selenium we use following code.
element1.click();

If we have  checkbox then how to chech uncheck?

element1.click(); //for check
element1.click(); //for uncheck

we use same code again because in second click if not checked then will be checked.
We can check element1.isSelected() for check checkbox selected or not.

if we have radio button then how to toogle?

We use click() method on web element object as below.
element1.click();


CHECKBOX and radiobutton Example java code:-


"package pkg1;

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver; 
import org.openqa.selenium.*; 

public class MyClass5_webelements_radiobutton_checkbox {   
    public static void main(String[] args) {       
     
        System.setProperty(""webdriver.chrome.driver"",""C:\\Users\\Desk-105\\Documents\\SELENIUM\\chromedriver.exe"");   
        WebDriver driver = new ChromeDriver();   

        driver.get(""https://www.onlinetutorial.info/p/selenium-checkbox-and-radiobutton.html"");   
        WebElement radio1 = driver.findElement(By.id(""radio_1""));     
        WebElement radio2 = driver.findElement(By.id(""radio_2""));     
        WebElement radio3 = driver.findElement(By.id(""radio_3""));           

        radio3.click(); 
        System.out.println(""Radio Button 3rd will be selected"");
       
       
        WebElement opt1 = driver.findElement(By.id(""checkbox_1""));     
        opt1.click(); 
        if (opt1.isSelected()) {   
            System.out.println(""Checkbox is Toggled On i.e selected"");   
        } else { 
            System.out.println(""Checkbox is Toggled Off i.e not selected"");   
        } 
  //driver.close(); 
         
    } 
}

Thursday, February 14, 2019

Locators in selenium

What is locators?

Selenium provides a number of Locators to precisely locate a GUI element.
There are many locators for select particular element .

There are mainly 7 locators:-

a)id
b)name
c)className
d)cssSelector
e)tagName
f)linktext
g)xpath

1.id locator:-

ID locator for get access to particular element . This loccator work with  id of element.
Example:- <input type="text"  id="id_002">
Example in code:- driver.findElement(By.id("id_002"))

2.className locator: -

className is locator for get access to particular element . This loccator work with  className of element.
Example:- <input type="text"  class="id_002">
Example in code:- driver.findElement(By.className("class1"))

3.Name locator:- 

This locator for get access to particular element . This loccator work with  className of element.
Example: - <input type="text"  name="name">
Example in code:- driver.findElement(By.name("name"))

4.HTML tag Name locator:- 

This locator used for get access to particular element by using tag name.
Example: - <input type="text" >
Example in code:- driver.findElement(By.tagName("input"))

5.link Text locator:-

LinkText locator is used for get acess element by using hyperlinks. If there will be many hyperlinks then top first will be selected.
Example:- findElement(By.linkText("LinkText"))

6.CSS selector:-   


TAG and ID:-
findElement(By.cssSelector(tag#id))

TAG and class:-
findElement(By.cssSelector(tag.class))

TAG and attribute:-
findElement(By.cssSelector(tag[attribute=value]))

TAG and class and attribute:-
findElement(By.cssSelector(tag.class[attribute=value]))

Example:- <input type="text" id="id_003"><br>
Example in code:-driver.findElement(By.cssSelector("input#id_003"))

7.Xpath locators:-


This locator is used in xml documents navigation mostly. Xpath stand for XML path.
Example:- Xpath=//tagname[@attribute='value']
Example in code:- findElement(By.xpath("XPath"))

There are two types of xpath absolute and relative.
We mostly use relative xpath because absolute xpath will be much more in length.

Example with html code:-

<html>
 <head></head>
<body> <div><h1>Heading…</h1></div></body>
</html>

Here absolute path for H1 tag will be         html/body/div/h1
Here relative path for h1 is                          //html/body/h1/text()


All locators Example with java code:-


package pkg1;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class MyClass4_locators {
@SuppressWarnings("static-access")
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String baseUrl = "https://www.onlinetutorial.info/p/locators-example.html";
    driver.get(baseUrl); 
    
    
     WebElement  email = driver.findElement(By.name("myname"));  
     email.sendKeys("pradeepyadav"); 
    
        driver.findElement(By.id("id_002")).sendKeys("sandeep yadav");  
    driver.findElement(By.className("class1")).sendKeys("rahul yadav"); 
    driver.findElement(By.tagName("input")).sendKeys("rohit");
        
    driver.findElement(By.cssSelector("input#id_003")).sendKeys("A");
    driver.findElement(By.cssSelector("input.class2")).sendKeys("B");
    driver.findElement(By.cssSelector("input#awe[type=text]")).sendKeys("C");
    driver.findElement(By.cssSelector("input.class3[type=email]")).sendKeys("D");
 
    
}

}

Wednesday, February 13, 2019

Selenium commands and use

Comands with Explaination

driver.get("url")
//It automatically opens a new browser window and fetches the page that you specify inside its parentheses
driver.getTitle() //Fetches the title of the current page
getPageSource() //Returns the source code of the page as a String value
getCurrentUrl() //Fetches the string representing the current URL that the browser is looking at
getText()          //Fetches the inner text of the element that you specify

navigate().to() //It automatically opens a new browser window and fetches the page that you specify inside its parentheses.
navigate().refresh() //Refreshes the current page
navigate().back() //Takes you back by one page on the browser's history.
navigate().forward() //Takes you forward by one page on the browser's history
webdriver.close() //It closes only the browser window that WebDriver is currently controlling.
webdriver.quit() //It closes all windows that WebDriver has opened


To getting access on  elements in a Frameor popup, we should first direct WebDriver to focus on the frame or pop-up window first before we can access elements within them.

1. Focus ON Frame  or swithing frame example.
driver.switchTo().frame("classFrame");
driver.findElement(By.linkText("Deprecated")).click();

2.Focus on popup or swithing to popup example.
driver.switchTo().alert(); //swithing popup
driver.switchTo().alert().accept(); //closing popup 

Selenium program example

Here is simple program to fill email id and password in facebook page.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class MyClass2 {

public static void main(String[] args) {
  System.setProperty(""webdriver.chrome.driver"",""C:\\Users\\Desk-105\\Documents\\SELENIUM\\chromedriver.exe"");
  WebDriver driver = new ChromeDriver();
  String baseUrl = ""http://www.facebook.com"";
     driver.get(baseUrl);
     WebElement  email = driver.findElement(By.id(""email""));
     email.sendKeys(""namo@onlinetutorial.com"");
     WebElement pwd = driver.findElement(By.id(""pass""));
     pwd.sendKeys(""12345678"");
   
}

}

How to install selenium in windows

How to install selenium webdriver with java?

You need 4 things to donload and install.
1.JDK
2.eclipse
3.selenium jar files
4.Browser driver exe file.

1.How to install JDK:-
Download JDK 1.8 version from below website 32 or 64 bit as your system need.
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Install JDK and set path in environment variable.

2.Download eclipse IDE java editor from below link.
https://www.eclipse.org/downloads/packages/release/luna/sr2/eclipse-ide-java-developers
and then Unzip file and  open eclipse.exe
when open eclipse editor then create a simple java project.


3. Selenium webdriver  import in eclipse's java project.
Selenium webdriver is just jar files you should download from below link.
https://www.seleniumhq.org/download/
Download java version driver.
You have already created a simple java project in eclipse. Now go to the project build-path and add
exterlal jar libraries. And select your webdriver jar files.
Now webdriver import done.


4. Browser webdriver exe file installation:--
You need to download this file from below link . Here I am goin to give link
of chrome browser exe because we use chrome browser in this tutorial.
http://chromedriver.chromium.org/downloads

Selenium Introduction

What is selenium?
Selenium is tool for automation testing.
Selenium automate browsers for software functionality testing.

Type of selenium tools:-
1.Selenium IDE.
2. Selenium RC(Remote control)
3.Selenium Webdriver
4.Selenium GRID

1.Selenium IDE:-
This is a recording of event in browser which can be execute after recording.
There is no code writing.

2. Selenium RC(Remote control)
This is autodated and not more useful. This is selenium
This RC also not provide any programming support to write code for selenium.

3.Selenium Webdriver:-
This is best tool for automation testing. With different programming
languages you can write web-driver selenium code and test software functionality.

4.Selenium GRID:-
Useful for executing a test on different machine and on different browser in parallel.
So this save time for test execution.

Conclusion:-

Selenium Webdriver is best . In next chapter we will learn about selenium webdriver.

About Me

My photo
Mumbai, Maharashtra, India