Monday 23 September 2013

Capturing the Sub Menu values using Selenium Web Driver

This program opens url and prints all submenu of Home menu.

import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class ReadSubMenu {

public static void main(String[] args) {
WebDriver driver = new FirefoxDriver(); //object created to start firefox driver

Actions action = new Actions(driver); // object created to perfomr mouse operation

driver.get("http://demo.lateralcode.com/css-drop-down-menus/"); // open url

WebElement home = driver.findElement(By.linkText("Home")); // find home menu

action.moveToElement(home).build().perform(); //put mouse pointer on Home menu

List we = home.findElements(By.xpath("//*[@id='menu']/ul/li[1]/ul/li")); // common property of all sub menu item

//travers through all submenu & print their text
for (int i =0; i
{
System.out.println(we.get(i).getText()); //print submenu text
}
 }

}

Tuesday 17 September 2013

HP QTP :- What is the file extension of the script file and OR in QTP

In QuickTest Professional, File extension is as follows –

·        Per test object rep: filename.mtr
·        Shared Object rep: filename.tsr
·        Code file extension id: script.mts

Monday 16 September 2013

Selenium : - Code to Login into drobbox.com

Code to Open dropbox.com & login is as follows - 

WebDriver driver; //declare object of WebDriver

driver = new FirefoxDriver(); //create object reference of Firefox driver

driver.get("http://dropbox.com"); //open dropbox.com

String parent = driver.getWindowHandle(); //read & store windows handle of parent browser

driver.findElement(By.linkText("Sign in")).click(); //click on Sing In link

//Switch to new window opened

for(String winHandle : driver.getWindowHandles()){ //iterate through all window open

   driver.switchTo().window(winHandle); //put focus to child browser window

}

driver.findElement(By.cssSelector("*[id='login_email']")).sendKeys("hello");//enter email

driver.findElement(By.cssSelector("*[id='login_password']")).sendKeys("hello"); //enter password

driver.findElement(By.name("login_submit_dummy")).click(); //click on Sign In button

driver.switchTo().window(parent); //return the control to parent browser

Friday 13 September 2013

Selenium : How to switch to Web Dialog window & back to Parent Browser Window

Steps are as follows -

           1.  Before clicking the link, get the handle id of the browser window.
                  String BrowserParent = driver.getWindowHandle();

     2.  After clicking the link & once Web Dialog is opened
                 String str = driver.getWindowHandle();
                 driver.switchTo().window(st); // switch to child browser

     3.  Once the operation on the web dialog box is completed.    
                driver.switchTo().window(BrowserParent); //return back to Browser window

What is the use of desired capabilities

Selenium desired capabilities allows to set/change a lot of browser capabilities like cookies, profile, set proxy etc..


It helps to handle cookies, SSL certificate alerts, file upload/save(in Firefox) etc.