Friday, January 17, 2014

For Multiple windows handles code Reusability

package Sample;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
public class MultipleWindows extends Login
{
        public static void MultiWindows(WebDriver driver, String Searchfor, String value, String Search)
        {
                Set<String> winHandleBefore = driver.getWindowHandles();
                Iterator<String> it = winHandleBefore.iterator();
                String mwin= it.next();
                String Pwin = it.next();
                driver.switchTo().window(Pwin);
               
// Fetching the Member details from the Search Member Pop Up window.
               
            driver.findElement(By.name(Searchfor)).sendKeys(value);
                driver.findElement(By.name(Search)).click();
             
            driver.switchTo().window(mwin);
        }
}

 

 

Note : use the below method where ever multiple windows are opened.

 

MultipleWindows.MultiWindows(driver, "txtSearchFor", "value"), "PropertyName");


No comments:

Post a Comment

TestNG - Can i use the 2 different data providers to same @test methods in TestNG?

public Object [][] dp1 () { return new Object [][] { new Object [] { "a" , "b" }, new Obje...