Encountering an issue when trying to choose the start date

When attempting to select the From-Date on "opensource-demo.orangehrmlive.com" Dashboard > Apply leave, I encountered an issue where I was unable to click on the from-date textbox.

driver.findElement(By.id("applyleave_txtFromDate").click();
Select secMonth = new Select(driver.findElement(By.xpath("//div[@class='ui-datepicktitle']/select[1]")));
secMonth.selectByVisibleText("Jan"); 
Select secYear = new Select(driver.findElement(By.xpath("//div[@class='ui-datepicker-title']/select[2]")));
secYear.selectByVisibleText("2021");
        
java.util.List<WebElement> dates = driver.findElements(By.xpath("//td[@data-handler='selectDay']"));
int count = dates.size();
for(int i=0; i<count; i++)
{
    String ReqD = dates.get(i).getText();
    if(ReqD.equalsIgnoreCase("2"))
    {
        dates.get(i).click();
        break;
    }
}

Answer №1

Having trouble getting it to function properly?

String currentDate = "2022-03-15";
WebElement inputDate = driver.findElement(By.id("input_date_field"));
inputDate.click();
inputDate.sendKeys(currentDate);
inputDate.sendKeys(Keys.ENTER);

Answer №2

One suggestion I have is to utilize AppConstants for storing all final values. This way, it will be simpler to pass them using String variables (for example: public static final String DATE_VALUE = "12/22/2020";). I find this method particularly helpful in automation testing, as when using scripts for long-term regression testing purposes within a framework, issues may arise if the calendar month changes. In such cases, script updates would be necessary. However, by passing values within String variables, the script would not require any modifications.

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

Unable to interact with a button using Selenium

I have been working on automating a process that involves clicking multiple buttons. I've made significant progress, but there's one button that I just can't seem to get to work. I'm using Python with Selenium for this task. No matter w ...

Establishing the exterior façade prior to generating the Docker image

I am currently new to Docker and in the process of dockerizing some applications. The project structure consists of: -PlayProject -------app ----------controllers ----------models ----------views -------ci -------conf -------project -------public ---- ...

Can you tell me the distinction between using RemoteWebDriver's executeScript() and Selenium's getEval() for executing

Can you explain the distinction between these two pieces of code: RemoteWebDriver driver = new FirefoxDriver(); Object result = driver.executeScript("somefunction();"); and this: RemoteWebDriver driver = new FirefoxDriver(); Selenium seleniumDriver = ne ...

What are the steps for setting up and executing NUnit/WebDriver test suites in Visual Studio?

After transitioning from a Java-JUnit4-Webdriver setup to a C#-NUnit-Webdriver one, I found myself missing the convenience of creating test suites in Eclipse. In Eclipse, I could easily compile test classes into a test-suite class and run them as JUnit tes ...

Unable to associate data with ModelAttribute list attributes in Spring MVC

In my current setup, I am utilizing Spring MVC along with AJAX to retrieve data from the server Here is a snippet of my ModelAttribute class: @Data public class PromotionSettingCriteria extends BaseRequest{ private Long[] promotionIds; private L ...

Exploring the automated retrieval of data from arrays in Java objects: A comprehensive guide

My goal is to automatically create Java objects from JSON data obtained from a REST API. The JSON array contains properties of different shops, and I aim to generate one object per shop with all its respective properties. The following code helped me achi ...

Access the freshly launched URL

I am relatively new to PHP and have a table displayed on my webpage. Each row in the table has an auto-incremented rowid that is not being displayed. When clicking on a row, it opens a new page in the format of www.newpage.com/newpage/rowid. If I inspect ...

Employing Python with Selenium to programmatically click on a button with a ng-click attribute and automatically upload

I am completely new to using Python and Selenium, but I have a task that requires me to automate file uploads with Selenium. There is a button that needs to be clicked which will launch a window for selecting the file to upload. Here is the HTML code fo ...

Obtain JSON array by utilizing the Simple Json Library

Here is a glimpse of my JSON data structure. {"Users":[ {"Username":"Admin1", "Password":"123"}, {"Username":"Admin2", "Password":"456"}, {"Username":"Admin3", "Password":"789"} ]} I'm attempting to retrieve all the usernames and passwor ...

The REST Client is reporting back with an HTTP status code of 401

Thank you for taking the time to read this! Overview: I have developed a JAVA REST client that authenticates with a username and password, returning a JSON response. Issue: I am encountering the following exception: Error in thread "main" java.io.IOExc ...

When using Eclipse, each workspace must have a unique project name in order to save properly

Hey there! I've done some research on this topic already. It seems that in Eclipse, if you utilize different workspaces, you should be able to save projects with the same name. However, I am encountering difficulties in doing so and I'm not sure ...

PhantomJS with Selenium encounters ElementNotVisible error when selecting a combo box, whereas Firefox performs without any issues in the same

I am working on a website that features a unique combo box where items are selected from divs instead of traditional options. My program needs to click on the combo box, wait (I've found using implicitly_wait(3) for 3 seconds works best), and then sel ...

Performing Load Testing using JMeter

After creating a test case using Selenium WebDriver and JUnit, I found myself needing to test it for over 100 users. However, due to limitations with my memory, I am unable to open that many browsers at once. I attempted to use threads in the application, ...

Having trouble finding elements with XPath in Python

While attempting to extract website information from firms listed on Bloomberg using XPath, I encountered a challenge as the results came back empty. After conducting multiple tests, it became evident that I was unable to locate any elements on the webpage ...

Comparing a single option in a dropdown list with all the other options using Selenium WebDriver and Java

Is there a way to retrieve all the options from a dropdown list and compare them with a single option using Selenium WebDriver? I attempted to do this using the following code: Select dropdown = new Select(_driver.findElement(EventListOptionList)); ...

Tips for managing popup browsers in Robot Framework

When using Robot Framework, I encountered a challenge with handling pop up browsers to allow access to the camera. The issue arises when trying to press Enter on the selected 'Allow' button after navigating there via the TAB key. Despite various ...

Issue with data interpretation between jQuery and Java

My character encoding is currently set to ISO-8859-1. I'm utilizing an AJAX call with jQuery.ajax to communicate with a servlet. After serialization by jQuery, the URL appears as follows: https://myurl.com/countryAndProvinceCodeServlet?action=getPro ...

"I'm trying to figure out the best way to use Selenium and Python to send a character sequence to a contenteditable element that has its attribute set

Recently, I've been experimenting with using Python 3.6 and Selenium to automate a simple task - logging into a chat website and sending messages automatically. is the webpage where I want to send the messages. Despite my limited experience with Py ...

Mastering the process of running selenium automation scripts (written in Java) with Safari Technology Preview

Seeking assistance with running automation scripts on Safari. Currently utilizing Selenium Webdriver scripts on Mac OS (High Sierra) and Safari 11.1.2 I've added the WebDriver Extension to the Safari browser and enabled 'Allow Remote Automation ...

Is it possible to create a mapping for the jsonProperty of nested fields in an object?

In my project, I have created two classes named Car.java and Bus.java. Car.java private Property property; Bus.java private Property property; The Property.java class contains attributes for number and colour. ...