package window;
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;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;
public class WindowHandling {
public static void main(String[] args) throws InterruptedException
{
WebDriver driver=new FirefoxDriver();
driver.get("https://www.irctc.co.in/");
driver.findElement(By.linkText("Hotels")).click();
//==================window handling method======================
Set<String> winhandle=driver.getWindowHandles();
//====================Getting id from all window=============
Iterator<String> it=winhandle.iterator();
String Parentwin=it.next();
String ChildWin=it.next();
driver.switchTo().window(ChildWin);
driver.findElement(By.xpath("//img[@alt='Ginger Hotel']")).click();
Thread.sleep(3000);
Set<String> winhandle1=driver.getWindowHandles();
Iterator<String> it1=winhandle1.iterator();
Parentwin=it1.next();
ChildWin=it1.next();
String SubChildWin=it1.next();
driver.switchTo().window(SubChildWin);
driver.findElement(By.cssSelector("#air_fromrowed > a > img")).click();
driver.findElement(By.linkText("29")).click();
driver.findElement(By.cssSelector("#air_fromrowed1 > a > img")).click();
driver.findElement(By.linkText("6")).click();
driver.findElement(By.linkText("6")).click();
driver.findElement(By.cssSelector("input.grbtn")).click();
Thread.sleep(3000);
driver.findElement(By.id("roomType0")).click();
Select sel=new Select(driver.findElement(By.id("noOfRooms0")));
List<WebElement> lst=sel.getOptions();
System.out.println(lst.size());
for(int i=0;i<lst.size();i++)
{
String Roomno=lst.get(i).getText();
if(Roomno.equals("1"))
{
sel.selectByIndex(i);
}
}
}
}
No comments:
Post a Comment