Showing posts with label WebDriver. Show all posts
Showing posts with label WebDriver. Show all posts

Tuesday, August 2, 2011

How to Handle Pop Up window.

final Set<String> beforeHandles = fatwire.getWindowHandles();
            System.out.println("window before:" +beforeHandles);
            Thread.sleep(4000);
           fatwire.findElement(By.xpath("//input[@value='Create']")).click();

 
           new WebDriverWait(fatwire, 30){ }.until(
                 new ExpectedCondition<Boolean>(){
             
                public Boolean apply(WebDriver driver) {

                     return (driver.getWindowHandles().size() > beforeHandles.size()) ? true :
                    false;

                }});
          
          new WebDriverWait(fatwire,30);
             
          Set<String> afterHandles = fatwire.getWindowHandles();
          afterHandles.removeAll(beforeHandles);
          String newWindowHandle = afterHandles.iterator().next();

          fatwire.switchTo().window(newWindowHandle);

Friday, July 1, 2011

How to Upload a file using Web Driver

Here we will be using webdriver to upload a file which is the easiest.

Example:


 @Test
    public void opentest() throws Throwable{
   
        // uploading the file from 2shared.
        driver.get("http://www.2shared.com/");
        driver.findElement(By.xpath("//input[@id='upField']")).sendKeys("C:\\Documents and Settings\\saik\\Desktop\\5-16-2011 11-02-21 AM.png");
        driver.findElement(By.xpath("//input[@type='image']")).click();


Friday, June 10, 2011

How to print the values from the drop down



List<WebElement> we = driver.findElements(By.xpath("//select[@name='lr']//option"));       

System.out.println("*****  " +we.size() );
              
 for (int i=1;i<we.size();i++){
                    System.out.println("the values are : " + we.get(i).getText());
                }

}