0

Am practicing on Spice jet site to automate.Here am giving code what i have wrote.

package NewPackage;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

public class HandlingStaticDropdowns 
{
  public static void main(String[] args)throws Exception
  {
    System.setProperty("webdriver.chrome.driver","C:\\SeleniumJars\\chromedriver.exe");
    WebDriverdriver=new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
    driver.get("https://www.spicejet.com/");
    Select s = newSelect(driver.findElement(By.id("ctl00_mainContent_ddl_Adult")));
    s.selectByValue("3");
    s.selectByIndex(6);
    s.deselectByVisibleText("5");
  }
}

Am not getting proper output. Please help me out and let me know what I did wrong.

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

1 Answers1

0

The PASSENGERS field contains of 3(three) , one for the number of Adult, one for the number of Child and the other for the number of Infant. To select 5 for Adult, 3 for Child and 1 for Infant you need to to induce WebDriverWait for the visibilityOfElementLocated() and you can use the following Locator Strategies:

  • Code Block:

    public class A_demo 
    {
        public static void main(String[] args) throws Exception 
        {
            System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
            ChromeOptions options = new ChromeOptions();
            options.addArguments("start-maximized");
            options.setExperimentalOption("useAutomationExtension", false);
            options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
            WebDriver driver =  new ChromeDriver(options); 
            driver.get("https://www.spicejet.com/");
            new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div#divpaxinfo"))).click();
            Select selectAdult = new Select(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div#divpaxOptions div.passengers-wrap2 p>select[name$='_Adult']"))));
            selectAdult.selectByVisibleText("5");
            Select selectChild = new Select(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div#divpaxOptions div.passengers-wrap2 p>select[name$='_Child']"))));
            selectChild.selectByVisibleText("3");
            Select selectInfant = new Select(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div#divpaxOptions div.passengers-wrap2 p>select[name$='_Infant']"))));
            selectInfant.selectByVisibleText("1");
        }
    }
    
  • Browser Snapshot:

spicejet_passengers

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