WebDriver to handle multiple browsers-Example

WebDriver fd = new FirefoxDriver();
fd.get("http://onlinesbi.com");
read.sleep(5000);

/////////click on login button
fd.findElement(By.xpath("/html/body/div/div[4]/div/div/h3/a[2]")).click();
Thread.sleep(3000);

//////click About OnlineSBI  Link
fd.findElement(By.linkText("About OnlineSBI")).click();
Thread.sleep(3000);

Set windowIds = fd.getWindowHandles();
Iterator iter = windowIds.iterator();
String mainwindid = iter.next();
String newwindid = iter.next();

////////select the new window and focused and click on close button
fd.switchTo().window(newwindid);
Thread.sleep(2000);
fd.findElement(By.xpath("/html/body/p/input")).click();


///////change focus to main window again & click continue to login

fd.switchTo().window(mainwindid);
fd.findElement(By.xpath("/html/body/div/table/tbody/tr[2]/td/table/tbody/tr[4]/td[2]/a/img")).click();

Comments