Wednesday, March 20, 2013

How to convert from Sql Blob to String in Java

            Blob blob=rset.getBlob("content");

            int blobLength = (int) blob.length(); 

            byte[] blobAsBytes = blob.getBytes(1, blobLength);

            ByteArrayInputStream bo = new ByteArrayInputStream(blobAsBytes);

            ObjectInputStream bis = new ObjectInputStream(bo);
           
            Map map = (Map)bis.readObject();

            String category=map.toString();

Tuesday, February 26, 2013

How to close the alert/Popup window in webdriver


//Click a link which will open the alert (like, open a File open/save window)

driver.findElement(By.linkText("amazon_referrals_2009.xlsx")).click();

//Now it will open a File open/save window

 Alert alert = driver.switchTo().alert();
 alert.accept();

//Now the newly opened window will be closed

Monday, February 25, 2013

How to work with Internet Explorer(IE) browser using Webdriver.


Download the "IEDriverServer.exe" and keep it in your local storage.

http://code.google.com/p/selenium/downloads/list


How to define:

System.setProperty("webdriver.ie.driver","Specify the "IEDriverServer.exe" file path);

//File path example: "C:\\Sakthi\\Softwares\\IE Driver\\IEDriverServer.exe".

WebDriver driver=new InternetExplorerDriver();

driver.get("http://spreadsheetpage.com/index.php/file/");


Code Example:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class ClosePopupIE
{
    public static void main(String[] args)
    {
        try
        {
        System.setProperty("webdriver.ie.driver","C:\\Sakthi\\Softwares\\IE Driver\\IEDriverServer.exe");

        WebDriver driver=new InternetExplorerDriver();
        driver.get("http://spreadsheetpage.com/index.php/file/");
        driver.findElement(By.linkText("amazon_referrals_2009.xlsx")).click();
       driver.close();
        }
        catch(Exception e)
        {
            System.out.print(e);
        }

    }     
  
}

Sunday, February 24, 2013

Handling child windows using Web Driver

//Click on link which will open new Link

             driver.findElement(By.linkText("Search settings page")).click();

// Now we have two windows and store them in to object array

            Object[] currentWindow =driver.getWindowHandles().toArray();

//In the array, first index is Parent window next is child window

            String ParentWindow=currentWindow[0].toString();
            String ChildWindow=currentWindow[1].toString();

//To work on child window

            driver.switchTo().window(ChildWindow);

//Now you are in child window, If you want go back to parent window

            driver. close()   // It will close the child window.  (Optional.If you dont want to close the first window, this step is not required.)

            driver.switchTo().window(ParentWindow);