Eknath Dhauskar
Eknath Dhauskar

Reputation: 25

How to select specific flight record on flight selection page, using Selenium webdriver

I am able to navigate to Flight Reservation page on website - http://www.spicejet.com/. Code is given below:

Code:

package Flight_Reservation;

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.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class NewFlight_OneWay {

public static void main(String[] args) {
    // TODO Auto-generated method stub

    System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\Selenium_Practice\\EXEs\\geckodriver-v0.10.0-win64\\geckodriver.exe");

    WebDriver driver = new FirefoxDriver();

    driver.get("http://www.spicejet.com/");

    driver.manage().window().maximize();

    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

    driver.findElement(By.xpath("//input[@id='ctl00_mainContent_rbtnl_Trip_1']")).click();

    //Select origin
    driver.findElement(By.id("ctl00_mainContent_ddl_originStation1_CTXT")).sendKeys("DEL");

    driver.findElement(By.linkText("Delhi (DEL)")).click();

    //Select destination
    driver.findElement(By.id("ctl00_mainContent_ddl_destinationStation1_CTXT")).sendKeys("BOM");

    driver.findElement(By.linkText("Mumbai (BOM)")).click();

    WebElement DateWidget = driver.findElement(By.id("ui-datepicker-div"));
    List<WebElement> columns = DateWidget.findElements(By.tagName("td"));

    for (WebElement cell: columns)
    {
        if (cell.getText().equals("24"))
        {
            cell.findElement(By.linkText("24")).click();
            break;
        }
    }

    Select AdultDropdown = new Select(driver.findElement(By.id("ctl00_mainContent_ddl_Adult")));

    AdultDropdown.selectByValue("2");


    Select ChildrenDropdown = new Select(driver.findElement(By.id("ctl00_mainContent_ddl_Child")));

    ChildrenDropdown.selectByValue("1");


    Select InfantDropdown = new Select(driver.findElement(By.id("ctl00_mainContent_ddl_Infant")));

    InfantDropdown.selectByValue("1");


    Select CurrencyDropdown = new Select(driver.findElement(By.id("ctl00_mainContent_DropDownListCurrency")));

    CurrencyDropdown.selectByValue("INR");


    driver.findElement(By.id("ctl00_mainContent_btn_FindFlights")).click();

}

}

Question:

On flight selection page, I want to select flight record radio button with flight name 'SG 161'. Please let me know how can I achieve that?

Upvotes: 1

Views: 5014

Answers (1)

Andersson
Andersson

Reputation: 52665

Use following code to click on required radio-button:

driver.findElement(By.xpath('//input[@type="radio"][contains(@value, "SG~ 161")]')).click();

Upvotes: 1

Related Questions