You are on page 1of 1

1).

Switching between windows: Generally selenium will focus on the 1st window, w
henever the application moves to the next page or tab , selenium can t automatical
ly switch to that window so we need to make the selenium to switch to that lates
t window with the help of following syntax.
Webdriverreference.switchTo().window( "windowId" );
To get the window id we have a method in selenium is getWindowHandles();
public class switchtooooo {

public static String freshwid;


public static void main(String[] args) throws InterruptedException {
WebDriver wd=new FirefoxDriver();
wd.get("http:hdfc.com");
wd.findElement(By.xpath(".//*[@id='node-18']/div/div/div/div/div[2]/nav/
ul/li[2]/a/div")).click();
wd.findElement(By.xpath(".//*[@id='node-4']/div/div/div/div/div/section/div/
section[2]/article[2]/div/a")).click();
Set<String> s=wd.getWindowHandles();
Iterator<String>itr=s.iterator();
while(itr.hasNext())
{
freshwid=itr.next();
s=wd.getWindowHandles();
itr=s.iterator();
while(itr.hasNext())
{
freshwid=itr.next();
}
wd.switchTo().window(freshwid);
Thread.sleep(2000l);
wd.findElement(By.xpath(".//*[@id='block-views-e693e51d3efb33676083fb5f5afa2
9aa']/div/nav/ul/li[2]/a/span")).click();
for(String handle:wd.getWindowHandles())
{
wd.switchTo().window(handle);
}

You might also like