Issue with Selenium Testing: Struggling to choose a date from the calendar options

For some reason, I am facing an issue where I can't seem to select the date value from the calendar list. However, all the other tests are working perfectly fine.

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 ch1 {
    public static void main(String[] args) throws InterruptedException {
        // TODO Auto-generated method stub
         System.setProperty("webdriver.chrome.driver", "C://testing/chromedriver_win32/chromedriver.exe");
         WebDriver driver = new ChromeDriver();
         driver.manage().timeouts().implicitlyWait(5000, TimeUnit.MILLISECONDS);
         driver.get("https://www.via.com");
         try {
             driver.findElement(By.xpath("//div[@class='wzrk-button-container']/button[1]")).click();
         }
         finally {
             driver.findElement(By.xpath("//div[@class='element relElements airportElements']/input[1]")).sendKeys("BLR");
             driver.findElement(By.xpath("//div[@class='calendar-icon']")).click();
             Select s = new Select(driver.findElement(By.xpath("//*[@id='depart-cal']/div[3]")));
             s.selectByValue("19");

             driver.wait(5000);
        }
    }
}

Even though the text is being inputted and the calendar opens up as expected, I'm still unable to select the date correctly.

Answer №1

Instead of using a select element for the calendar, it was implemented as a div element. As a result, select will not work in this scenario.

Here is an alternative code snippet to try:

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.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class ch1 {

    static WebDriver driver;
    public static void main(String[] args) throws InterruptedException {
        try{
            System.setProperty("webdriver.chrome.driver", "C://testing/chromedriver_win32/chromedriver.exe");
            driver = new ChromeDriver();
            WebDriverWait wait = new WebDriverWait(driver, 15);
            driver.manage().timeouts().implicitlyWait(5000, TimeUnit.MILLISECONDS);
            driver.get("https://www.via.com");
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='wzrk-button-container']/button[1]")));
            driver.findElement(By.xpath("//div[@class='wzrk-button-container']/button[1]")).click();
            driver.findElement(By.xpath("//div[@class='element relElements airportElements']/input[1]")).sendKeys("BLR");
            driver.findElement(By.xpath("//div[@class='calendar-icon']")).click();
            WebElement date = driver.findElement(By.xpath("//*[@id='depart-cal']/div[3]//div[text()='19']"));
            wait.until(ExpectedConditions.visibilityOf(date));
            date.click();

        }
        catch(Exception e){
            System.out.println(e.getMessage());
        }
        finally{
            driver.quit();
        }
    }

}

Please let me know if this solution works for you.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to parse this JSON using Jackson?

My JSON data is structured like this: { "summary":{ "somefield1":"somevalue1", "Twilio":{ "field1":"value1", "field2":"value2" }, "Tropo":{ "field1":"value1", "field2":"va ...

Difficulty in finding element in iframe using ember and Selenium

This is my first time working on automation using cucumber. The UI is in an iFrame and built with ember by another team, so any changes to the UI are not feasible. I am attempting to locate a text field and populate it (the final step). However, I continu ...

A specialized subclass inheriting from another subclass of unittest.TestCase, featuring a unique setUpClass method

I have a custom subclass of unittest.TestCase specifically designed for running selenium tests: class FunctionalTest(unittest.TestCase): @classmethod def setUpClass(self): self.browser = webdriver.Firefox() self.browser.implicitly ...

Avoid creating reports during Maven build execution

I'm encountering an issue with my Maven build process. I have multiple reporting plugins set up in the project, and every time I run Maven → clean, it clears the reports causing the Maven → build to fail with a FileNotFoundException error. Is ther ...

Is it possible to automate Chrome browser using Selenium without using chromedriver?

I've been attempting to automate a website but have encountered issues with detecting chromedriver. Despite trying various methods such as changing the cdc_ part of the chromedriver and using a different user agent, it still identifies the presence of ...

Testing your login functionality with RSpec, Capybara, and Selenium

I'm currently working on passing the login test using rspec integration testing. Although I have set up rspec and confirmed that it's functioning properly, the test is not successfully passing. Below is the code snippet: require 'spec_helpe ...

WebDriver is not recognized as a type and ChromeDriver cannot be resolved as a type

Despite using the latest versions listed below, I am still encountering the issue mentioned above. Can anyone provide assistance? Eclipse IDE Version: 2019-12 (4.14.0); WebDriver (Java) - 3.141.59 ChromeDriver 79.0.3945.36 Below is the code snippet: pa ...

What is the best way to check if a function has been successfully executed?

When working with PDF documents, I often use an instance of pdfkit document known as doc: import PDFDocument from 'pdfkit' const doc = new PDFDocument() This doc instance is then passed into a function called outputTitle: export const outputTi ...

ChromeDriverService and Azure Pipelines Agents

Currently, I am automating Selenium tests in an Azure DevOps pipeline using C#. To improve debugging, I recently updated my code to include ChromeDriver logs, requiring me to make changes to utilize the ChromeDriverService. string binaryDir = Manag ...

TimeoutException thrown by Selenium script during web scraping of Indeed platform

My current project involves creating a script to scrape job listings on Indeed, extracting information such as title, company, location, and job description. The script successfully retrieves data from the first five pages, but encounters an issue with o ...

Encountering the Selenium Webdriver HTTP error within an Angular 4 project

ERROR Detected Issue found in: ./node_modules/selenium-webdriver/http/index.js Module not found: Error: Unable to locate 'http' in 'C:\Users\aprajita.singh\Documents\Angular 4\Auto-Trender-Project\node_modules ...

Discovering the source of an error in Jest: Unveiling the stack trace and cause

I am currently troubleshooting a nodeJS application. I encountered an error where a variable is undefined. When running the code without Jest, the error was clear and easily located: without jest: ➜ server git:(dc/build) ✗ node test/runner.js /Users/ ...

Is it possible to translate Selenium IDE test scripts to Selenium WebDriver tests using Java programming language?

When recording my tests with Ghost inspector, I can export them in Selenium IDE format. Can these exported tests be used to write future Selenium web driver tests in Java? The format of the exported tests appears as follows: Navigation waitForPageToLoad ...

During the execution of numerous automated tests on BrowserStack, the initial test is able to run successfully; however, the subsequent tests encounter an issue where the sessions are

Currently, I am setting up and running multiple automated tests using Cucumber and Selenium on BrowserStack. The first test scenario runs successfully, but starting from the second test, no session is established in BrowserStack. This leads to failure of t ...

Python code encounters a Selenium error while trying to click the video button

Struggling to automate the playback of my math online video through Selenium, but encountering a problem. Other elements on the page load before the video with the play button appears. I need a way to automatically trigger that button without any delays. ...

"Error encountered: java.lang.NoClassDefFoundError while attempting to execute a jar file using ant

Reaching out to the Selenium community in case anyone has encountered a similar issue while setting up selenium tests using Ant. I have tried multiple solutions posted on various forums, but I am still unable to resolve my issue. When I compile the code ( ...

Struggling to find a specific element on a website with Xpath in Selenium using Python

Attempting to retrieve data from a website named: , specifically targeting the element: /html/body/div[1]/div/main/div/div[2]/div/div[2]/div/div/div[1]/div[4]/div[2]/div[1]/div[1]/div[2]/span[2] which displays volume as a number on the webpage. The code I ...

Selenium C# is experiencing difficulties in running properly on localhost

I am attempting to scrape a website using Selenium and FireFox. While the Python code works fine, I encounter an issue in C# where I receive the error message: 'OpenQA.Selenium.WebDriverException: Cannot start the driver service on http://localhost:53 ...

What makes Selenium 2.0 unique in not requiring an external Firefox driver like IE and Chrome?

Can someone please help me with two questions I have? 1) I'm curious about why there isn't a Firefox driver [.exe] available for running selenium2.0, like there is for IE and Chrome. 2) Why is it necessary to initialize the IE and Chrome driver ...

Trouble accessing the browser - Session Creation Exception occurred

Here is a problem with the testcase code that I can't seem to get it to execute properly. Is there a configuration issue related to Firefox? package testOperations; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openq ...