Go to site : expedia.co.in and try to pick the dates
Script :
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JqueryDatePicker { | |
static WebDriver driver=null; | |
public static void main(String[] args) throws InterruptedException { | |
// TODO Auto-generated method stub | |
WebDriver driver = new FirefoxDriver(); | |
driver.navigate().to("http://www.expedia.co.in"); | |
Thread.sleep(9000); | |
WebElement calElement=driver.findElement(By.xpath("//*[@id='hotel-checkin']")); | |
calElement.click(); | |
Thread.sleep(3000); | |
WebElement table = driver.findElement(By.xpath("//*[@id='home-page']/div[24]/div/div/section[1]/ul")); | |
System.out.println("JQuery Calendar Dates"); | |
// store the date to pick.. | |
String date1 ="15"; | |
// all dates link are stored in li so create loop and then verify if date mathes and then click on the date and then break | |
List<WebElement>; cell = table.findElements(By.tagName("li")); | |
for (int i=1;i<cell.size();i++) { | |
System.out.println(date1); | |
// find a match if its 15 then click on the date and then break the loop | |
if (cell.get(i).getText().equals(date1)) { | |
// here date1 should substitute 15 | |
driver.findElement(By.linkText(date1)).click(); | |
break; | |
} | |
} | |
} | |
} |