Need some help.
I have written an automation script to find buses in RedBus, which provides source and destination cities, enter the dates on calendar and search.
Once I get the results, I get around 65 buses as available. I need to find the highest bus fare and click on View seats. I am able to get the list of travel names and fare for each travel. I am storing these details in a List<WebElelment>
Bus fares are returned in String. I somehow need to convert these bus fares to int and sort it to find out the lowest price of bus. Could someone help me.
public class RedBus {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id='txtSource']")).sendKeys("Bangalore");
driver.findElement(By.xpath("//*[@id='txtDestination']")).sendKeys("Mumbai");
driver.findElement(By.xpath(".//*[@id='txtOnwardCalendar']")).click();
WebElement currentDay = (new WebDriverWait(driver,10)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[@id='rbcal_txtOnwardCalendar']/table[@class='monthTable first']//td[@class='current day']"))) ;
currentDay.click();
driver.findElement(By.xpath(".//*[@id='txtReturnCalendar']")).click();
driver.findElement(By.xpath(".//*[@id='rbcal_txtReturnCalendar']/table[2]/tbody/tr[5]/td[4]")).click();
driver.findElement(By.xpath(".//*[@id='searchBtn']")).click();
Thread.sleep(12000);
List<WebElement> list= driver.findElements(By.xpath(".//*[starts-with(@id,'onwardTrip')]/div[2]/ul/li"));
System.out.println("Size="+list.size());
String busName="";
String busPrice="";
//Get all travels names and their respective prices
for (WebElement result : list ){
busName=result.findElement(By.className("BusName")).getText();
busPrice=result.findElement(By.className("fareSpan")).getText();
System.out.println("Price for " + busName + " is: " +busPrice);
}
//Need to find the highest bus price and click on View Seats -- Yet to be coded
driver.close();
}
}