1

How to click on the Round Trip radio button within SpiceJet website. It gets selected but after few seconds oneway is selected as default

Below is the code to automate spicejet website as on 11Novemeber 2020. Even if i click on Roundtrip radio button, by default oneway radio button gets selected. How do i resolve this issue?

package practice;

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

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Spicejet {

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

        System.setProperty("webdriver.chrome.driver",
                "C:\\Users\\User\\Desktop\\selenium\\chromedriver_win32 (1)\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.spicejet.com/");
        driver.manage().window().maximize();
        driver.findElement(By.xpath("//input[@value='RoundTrip']")).click();
        new WebDriverWait(driver, 20).until(ExpectedConditions
                .visibilityOfElementLocated(By.xpath("//input[@id='ctl00_mainContent_ddl_originStation1_CTXT']")))
                .click();

        driver.findElement(By.xpath(
                "//div[@id='glsctl00_mainContent_ddl_originStation1_CTNR']//table[@id='citydropdown']//li/a[@value='MAA']"))
                .click();
        driver.findElement(By.xpath(
                "//div[@id='ctl00_mainContent_ddl_destinationStation1_CTNR']//table[@id='citydropdown']//li/a[@value='BLR']"))
                .click();
        driver.close();
    }
}
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

Seems the SpiceJet web application needs some longer time to to attain document.readyState as complete.

So to click() on the associated with the text Round Trip you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    new WebDriverWait(driver, 30).until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));
    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("table.tblTrip input[value='RoundTrip']"))).click();
    
  • xpath:

    new WebDriverWait(driver, 30).until(webDriver -> ((JavascriptExecutor) webDriver).executeScript("return document.readyState").equals("complete"));
    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//table[@class='tblTrip']//input[@value='RoundTrip']"))).click();
    
  • Browser Snapshot:

Spicejet_RoundTrip


References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352