Search On Google

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.

Selenium Tutorial All Topics

Selenium Introduction?

How to install Selenium Webdriver?

Selenium webdriver program example

Selenium web elements

Selenium findElement vs findElements

Selenium click on href link and image

Selenium dropdown value select

Monday, February 11, 2019

What is Conditional Formating in MS Excel

What is conditional Formatting?
With conditional formatting you can change data color or
Background color of data by checking condition of data.

Example:-

Suppose you want to set every data greater than 18 year age will be in red then
It will be in red color by using conditional formatting functionality of excel."

How to use Conditional formatting in excel?
Step:-Click on HOME tab.
Step2:-Click on conditional formatting.
Step3:-There are some pre-defined rules will be available you can select.
Step4:-In every rule you set criteria greater, less, equal etc.
Step5:- A popup will appear to set criteria as you wish.
Step6:-done

Note:-
 You can clear conditional formatting also by going there at same location from where you have applied.

Example:-
 In image you will see full step by step explanation below.


What is Chart in MS Excel?

What is chart?
A chart is graphical representation of data. Charts are used for
Trend analysis of given data. With chart some one easily see
Graphical data up and down and other things.

Types of chart in MS Excel?

PIE chart
BAR chart
COLUMN chart
Line Chart
Combo chart

How to create Chart?
Step1:-Select your data
Step2;-Click on INSERT tab on ribbon.
Step3:- Click on chart.
Step4:-Select chart type as you wish.

Example:- Below 4 Graphical animation image is below for give full explanation.



Microsoft Excel How to insert formula in Cell

For inserting formula you have to write sign = in a cell where you want to apply formula. After write = sign you should write a letter . Now formula starting with that letter will be appear.

Example1:- Sum formula 
“=sum(C1,C3,C5)”
“=C1+C3+C5”
“=sum(A2:A20)”

 a)Above sum function will add all given 3 cells.
 b)You can write direct by equal sign.
c)Third one will add values from A2 to A20 i.e. in range addition

 Example2:- Substract formulas 
“=sum(C1,-C3,C5)”
“=C1-C3+C5”
“=sum(A2:A20)”

a)Above sum function will add and subtract.
 b)You can write direct by equal sign.
c)Third one will add and subtract values from A2 to A20 i.e. in range addition subtractions negative values will be subtracted.


Sunday, February 10, 2019

What are common MS Excel Formulas?

Common Formulas   
  
Formulas          Example                                          Description

SUM                 =SUM(E1:E18)”                          Add for range E1 to E18
COUNT           =count(E1:E18)”                          Count no of cells in range
MIN                  =MIN(E1:E18)”                            give minimum value from a range
MAX                 =MAX(E1:E18)”                           give maximum value from a range
AVERAGE       =AVERAGE(E1:E18)”                   give average value from a range
LEN                 =LEN(E1)"                                    give text length
SUMIF             =SUMIF(E1:E12,">10",E1:E4)”    perform addition based on criteria.
AVERAGEIF    =SUMIF(E1:E12,">10",E1:E4)”    perform average based on criteria.
NOW               =NOW()”                                      give current date and time
       
       
STRING FORMULA   
   
FIND             =FIND("li","online",1)                  =find(findtext, withintext, startnumber)”
REPLACE     =REPLACE("online",2,2,"of")     =replace(oldtext,startnumber,numberofchar,newtext”)”
LEFT            =LEFT("onlinetutorial",4)             return left 4 char
RIGHT         =RIGHT("onlinetutorial",4)           return right 4 char
ISTEXT        =istext(value)                               return true if value is text
MID              =MID("GURU99",5,9)                  return middle text of given range 5 to 9
       
       
DATE TIME FORMULA
       
DATE            “=DATE(2019,1,4) ”                          return date
DAYS            “=DAYS(E1:E3)”                               give no of days between given date range.
MONTH       “=MONTH("4/1/2019") ”                   return month only
MINUTES    “=MINUTE("12:31") ”                        return minutes from time value
YEAR          “=YEAR("4/1/2019") ”                        return year value
       
NUMERIC FORMULA       
       
ISNUMBER       “=ISNUMBER(E3) ”                  return true if value is numeric
ROUND            “=ROUND(3.18789,4)”             to get round off of given value
MOD                 “=MOD(10,8)”                          return remainder
RAND               “=RAND()”                               generate random number between 0 to 1
PI                      “=PI()”                                      return value 3.14 value of PI
POWER            “=POWER(5,3)”                      “=POWER(number,power)” will give 5^3=5*5*5 from example
ROMAN            “=ROMAN(2018) ”                  convert number to roman number
MEDIAN           “=MEDIAN(9,2,5,1,7) ”             calculate median of numbers as given





What is function/Formula in Excel

What is formula/Function in excel?

In MS Excel formulas are pre-defined or custom function which are evaluated by
Excel application to give a value result.


How to apply formula in excel?

For apply formula on a cell you should write equal sign then write formula.
Because cell start with sign equal “=” will be evaluated by excel to give result value.

Ways to apply formula in MS Excel:-

There are three way to apply formula in excel:-
1. Discrete value  formula:-
Example:- =6+7

2. Discrete cell address  formula:-
Example;- “=A2*D3/A1”

3.Pre defined formulas(functions)
Example: - "=SUM(E1:E3)"

Important point to remember for apply formula:-

Suppose you want to apply formula then please remember BODMAS concept will be applied.
If you do not know BOADMAS then please read BOADMAS concept given below for given example.

BOADMAS example:-

“=(A2 * D2) / 2.”
Expressions( brackets) are evaluated first.
And then division evaluated.
And then Multiplication evaluated.
And in last addition and subtraction occurs.




What are logical functions in MS Excel

Logical functions in MS Excel?

IFERROR

"=IFERROR(5/0,"Divide by zero error")”
To display custom text when error occures.

IF
"=IF(ISNUMBER(22),"Yes", "No")
Display custom text based on condition true or false.

AND
“=AND(1 > 0,ISNUMBER(1))
For check multiple condition in AND function.

OR
"=OR(D8="admin",E8="cashier")
Check condition true of a given multiple conditions.

TRUE
“=TRUE()

NOT
"=NOT(ISTEXT(0))


IFNA
"=IFNA(D6*E6,0)
To display alternate value if NA occures.

NESTED IF
"=IF(A1="Sunday","GO for movie",IF(B1="Saturday","enjoy weekend","Do your work"))

Nested if is not different from if condition . In nested if if condition occurs in the other outer if.




Saturday, February 9, 2019

What is grouping and un-grouping in MS Excel

What is grouping and un-grouping in MS Excel?


As the name of this grouping means a large data will be grouped
Based on some values . That value will head of the related data.

Example:-

In given example you will see that we have some country with some state
And we want to see all state in group with related country then we apply grouping
On country.

How to apply grouping in excel?

Below steps are given. All steps are also shown in given gif example.

Step1:-Click on DATA tab.
Step2:-Select all column and row of data.
Step3:- Click group data button.
Step4:- A  window will be open then select row and click ok.
Step5:- There are 3 options. Group and ungroup and subtotal.
Step:6:- Click sub total button to set criteria of count and summation of grouping data.

All above steps are shown in below GIF image:-





Friday, February 8, 2019

What is data filter in MS Excel

What is data filter?
Data filter is functionality to apply search criteria. Suppose you want to search some data with some specific name then you will be able to search.

Example:- Suppose you have data with multiple bank and a column you have bank then you can apply
Filter on bank column to see data of state bank only or any other bank which you will select.

How to apply filter in MS EXCEL?
Steps are given below:-

Step1:-Click on DATA tab in EXCEL.
Step2:- Select column to apply filter you want.
Step3:- Click on Filter option now filter will be applied on selected column.
Step4:- At first column you will see filter drop down will be seen .
Step5:- Click on this to search some specific name and select to filter out.
Step6: -You can apply here custom filter also by clicking on filter drop down.

Please see in GIF  example:-


What is data validation in MS Excel

What is data validation in MS Excel?
Data validation is good functionality to validate data to avoid mistakes or error at the time of
Data processing. Suppose a person entering data of PAN card then you can define length 10
For PAN card number entry. So this will help to write exact 10 text otherwise by mistake


How to apply data validation in MS Excel?

Ans:-Below steps are given to apply data validation.

Step1:- Click on DATA tab in EXCEL.
Step2:- Select a single cell or cell range where you want to apply data validation.
Step3:- Click on data validation drop down and then click on data validation .
Step4:- Now you will se a window with some tabs as below.
Step5:- Select validation criteria for your data in setting tab.
Step6:- Click on Error Alert tab in .
Step7:- Click on OK tab to save validation.

Now test your cells on which you have applied data validation.

Please see below example in GIF image for above data validation implementation.


Monday, February 4, 2019

How to Add Subtract Multiply And Divide In Excel


How to Add, Substract , Multiply and divide in Excel? 

Example1:- Sum formula
“=sum(C1,C3,C5)”
“=C1+C3+C5”
“=sum(A2:A20)”

a)Above sum function will add all given 3 cells.
b)You can write direct  by equal sign.
c)Third one will add values from A2 to A20 i.e. in range addition


Example2:- Subtract formulas
“=sum(C1,-C3,C5)”
“=C1-C3+C5”
“=sum(A2:A20)”

a)Above sum function will add and subtract.
b)You can write direct  by equal sign.
c)Third one will add and subtract values from A2 to A20 i.e. in range addition subtraction
negative values will be subtracted.




Example3:- Multiply formulas
“=C1*C3”
“=PRODUCT(C1:C3)”
“=PRODUCT(C1:C3, 3)”

a)Above multiply function will multiply direct
b)Multiply in range C1 to C3.
c)Multi ply in range from c3 to c1 and after in last multiply total with 3.



Example4:- Divide formulas
Note:  There is no DIVIDE function in Excel.
“=C1/C3”
divide  C1 with C3.





About Me

My photo
Mumbai, Maharashtra, India