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.

Thursday, 12 September 2013

JXL And POI, which api is better and why

  •      jxl does not support  XLSX files
  •      jxl exerts less load on memory as compared to ApachePOI
  •      jxl doesn't support rich text formatting while ApachePOI does.
  •      jxl has not been maintained properly while ApachePOI is more up to date.
  •      Sample code on Apache POI is easily avaialble

Wednesday, 11 September 2013

How to handle java script/error/exception alert using WebDriver

WebDriver would support handling js alerts using Alert interface.
         
          // Bring control on already opened alert
               Alert alert = driver.switchTo().alert();

          // Get the text/message of the alert or prompt
               alert.getText(); 
         
         // Click ok button of alert
              alert.accept();

         // Click Cancel button of alert
              alert.dismiss();