0% found this document useful (0 votes)
814 views2 pages

Red Bus

The document is a Java program that automates booking a bus ticket from Mumbai to Pune on the RedBus website using Selenium. It imports Selenium libraries, defines a RedBus class with a main method, launches ChromeDriver, navigates to RedBus, searches for tickets from Mumbai to Pune on a specified date, selects sleeper class, clicks on a bus option, proceeds to booking, selects a return date and clicks search, prints the names and prices of available buses, then closes the driver.

Uploaded by

Kavita Badgujar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
814 views2 pages

Red Bus

The document is a Java program that automates booking a bus ticket from Mumbai to Pune on the RedBus website using Selenium. It imports Selenium libraries, defines a RedBus class with a main method, launches ChromeDriver, navigates to RedBus, searches for tickets from Mumbai to Pune on a specified date, selects sleeper class, clicks on a bus option, proceeds to booking, selects a return date and clicks search, prints the names and prices of available buses, then closes the driver.

Uploaded by

Kavita Badgujar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

package Assignment;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class RedBus {

public static void main(String[] args) throws InterruptedException {


System.setProperty("webdriver.chrome.driver", "C:\\Users\\kavita
Badgujar\\Downloads\\chromedriver_win32 (2)\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

driver.get("https://www.redbus.in/");
driver.manage().window().maximize();

driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id='src']")).sendKeys("Mumbai");
driver.findElement(By.xpath("//li[@data-id='462']")).click();
driver.findElement(By.xpath("//*[@id='dest']")).sendKeys("Pune");
driver.findElement(By.xpath("//li[@data-id='130']")).click();

driver.findElement(By.xpath(".//*[@id='onward_cal"
+ "']")).click();
driver.findElement(By.xpath("//td[text()='7']")).click();
driver.findElement(By.xpath("//button[@id='search_btn']")).click();
driver.findElement(By.xpath("//label[@for='dtAfter 6 pm']")).click();
driver.findElement(By.xpath("//div[@class='close'] ")).click();
driver.findElement(By.xpath("//label[@for='bt_SLEEPER']")).click();
driver.findElement(By.xpath("//*[@id=\"root\"]/div/div[3]/div[2]
")).click();

driver.findElement(By.xpath("//*[@id=\"19000009\"]/div/div[2]/div[1]")).click();
driver.findElement(By.xpath("//*[@id=\"rt_19000009\"]/div/div/div/
div[3]/div[2]/div[2]/canvas")).click();

driver.findElement(By.xpath("//*[@id=\"19000009\"]/div[2]/div[2]/div[2]/div[2]/
div/div/div[2]/div/div/div[2]/div[1]/div/div[1]/div/ul/li[2]/div[1]/div")).click();

driver.findElement(By.xpath("//button[text()='Proceed to
book']")).click();
driver.findElement(By.xpath("//canvas[@data-type='lower']")).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);

driver.close();

You might also like