1

How to handle the calendar for the departure box and return box in selenium. Please check my code once website: https://www.goibibo.com/

public class goibibo {
    private static WebDriver driver = null;
    public static void main(String[] args) throws InterruptedException  {
        // TODO Auto-generated method stub
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.goibibo.com/");
        driver.manage().window().maximize();
        new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='gosuggest_inputSrc']"))).sendKeys("A");
        Thread.sleep(1000);
        List<WebElement> myList = new WebDriverWait(driver, 20).until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//div[@class='dib marginL10 pad0 textOverflow width90']/div/span")));
        for (int i = 0; i < myList.size(); i++)
        {
                System.out.println(myList.get(i).getText());
                if (myList.get(i).getText().equals("Ahmedabad"))
                {
                    myList.get(i).click();
                    break;
                }
            }
        new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"gosuggest_inputDest\"]"))).sendKeys("Mum");
        Thread.sleep(1000);
        List<WebElement> Dept = new WebDriverWait(driver, 20).until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath("//div[@class='dib marginL10 pad0 textOverflow width90']/div/span")));
        for (int j = 0; j < Dept.size(); j++)
        {
                System.out.println(Dept.get(j).getText());
                if (Dept.get(j).getText().equals("Mumbai"))
                {
                    Dept.get(j).click();
                    break;
                }
        }

        //Thread.sleep(3000);
        //driver.switchTo().frame("notification-frame-~2514428c7");
        //driver.findElement(By.xpath("//i[@class='wewidgeticon we_close']")).click();
        //pop-up frame
        WebDriverWait wait = new WebDriverWait(driver, 5);
        wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[starts-with(@name ,'notification-frame-')]")));
        WebElement element=wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//i[contains(@class ,'wewidgeticon')]")));
        element.click();

        //dates
        Thread.sleep(5000);
        driver.findElement(By.xpath("//*[@id=\"searchWidgetCommon\"]/div[1]/div[1]/div[1]/div/div[6]/input")).click();

        List<WebElement> allDates=driver.findElements(By.xpath("//*[@id=\"searchWidgetCommon\"]/div[1]/div[1]/div[1]/div/div[6]/div/div"));

        for(WebElement ele:allDates)
        {

            String date=ele.getText();

            if(date.equalsIgnoreCase("28"))
            {
                ele.click();
                break;
            }

        }

    }

}

Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="searchWidgetCommon"]/div[1]/div[1]/div[1]/div/div[6]/input"}

Dhru 'soni
  • 1,024
  • 7
  • 23
sharful
  • 15
  • 8
  • you are using incorrect xpath please try to find and read how to create proper xpath. – Dhru 'soni Apr 04 '19 at 09:06
  • driver.findElement(By.xpath("//input[@placeholder='Departure']")).click(); than get list of element List myList = driver.findElements(By.xpath("//div[@class='calDate']")); and get exact match of your desire date. – Dhru 'soni Apr 04 '19 at 09:06
  • still, it is not working driver.findElement(By.xpath("//input[@placeholder='Departure']")).click(); List allDates = driver.findElements(By.xpath("//div[@class='calDate']")); for(WebElement ele:allDates) { String date=ele.getText(); if(date.equalsIgnoreCase("28")) { ele.click(); break; } } – sharful Apr 04 '19 at 09:25

0 Answers0