Using Selenium Webdriver to open a JavaScript calendar popup window

While testing a basic website, I encountered an issue with the Firefox webdriver not displaying a Javascript calendar window when a button is clicked. Even though the Selenium IDE successfully spawns the window, running the Java code does not result in the window appearing.

The snippet of code used to click the Javascript element is:

WebElement element = driver.findElement(By.cssSelector("img[alt=\"Pick a date\"]"));
element.click();

Additional information: The 'cal.gif' image is also not visible when using the webdriver. The problem lies in getting the calendar window to appear rather than interacting with it after it's open.

You can find the website I am testing here: Parking Meter

I have extensively searched for a solution to this issue but have yet to find one. Any assistance or guidance would be greatly appreciated.

Edit: Here is the HTML code for the JS calendar:

<a href="javascript:NewCal('EntryDate','mmddyyyy',false,24)"
   <img height="16" width="16" border="0" alt="Pick a date" src="cal.gif"></img>
</a>

Answer №1

Your current approach is not correct. Make sure to select the a tag instead of the img tag when you click on it.

I have provided a sample code below that has been tested and is functioning properly:

@Test
public void validateLink() throws Exception
{
    driver.get("http://adam.goucher.ca/parkcalc/index.php");

    Thread.sleep(2000);
    driver.findElements(By.tagName("a")).get(0).click();
}

Adjust the index value in the code snippet above to either 0 or 1 based on your specific requirements.

Answer №2

To interact with elements on a webpage using JavaScript, I would utilize the JavascriptExecutor.

JavascriptExecutor js = (JavascriptExecutor)driver;

js.executeScript("JavaScript.click;");

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

Information is not appearing in the table

I'm having trouble displaying data in a table format. The issue arises when I try to fetch data from a JSON file using a custom service. The fetched data is then inserted into the $rootScope object. However, when I preview the view, it appears blank ...

What is the best way to retrieve certain fields from a Firestore database using Next.js?

Is there a way to access a specific field in a document using the user's uid as its name? I am utilizing useAuthState from react-firebase-hooks to retrieve the user's credentials (uid). https://i.sstatic.net/t1xGL.png This code snippet allows me ...

Use JavaScript to smoothly move a span to a specific location on the page

My challenge lies in enabling users to dynamically create a span at any desired location upon clicking the "Link" button. The issue I'm facing is that although I set the attribute draggable="true" for the dynamically created span, it remains fixed wit ...

Encountered an issue with adding an event to a class with different IDs

There seems to be a bug in this demo. I am trying to add the same event to the same class but with different IDs. The code looks like this: var self; var id; var result; var myArray=document.getElementsByClassName("tipDiv"); for (var i=0;i<myArray.len ...

The version of Selenium WebDriver is 3.0.1 and it is using chromedriver.exe 2.25 with no whitelisted IPs specified

I am in need of a solution that can open a Chrome browser and access a URL through a proxy. After careful consideration, I have opted to use the following tools: Selenium WebDriver 3.0.1 with Java 1.8.0_111-b14 chromedriver.exe 2.25 However, I have ...

Scrape hyperlinks when pagination is present, utilizing Selenium

After making some tweaks to my script, it now runs smoothly and flawlessly. I owe this success to the support I received on SO. Start by opening the URL as www.my.url Proceed to open all 20 links one by one and save their names However, upon closer ...

When downloading an app from the Google PlayStore, error 504 or error 108 may appear. What are the possible reasons for these errors in the code?

Encountering error code -504 or -108 when trying to download an app from the Play Store can be frustrating. After spending a year developing an app, signing it, and uploading it as Beta, everything seemed to be going smoothly. Despite thorough debugging an ...

Extracting URLs using Selenium from specific cells within a table

While parsing a webpage table, I noticed that one of the columns contains a hyperlink. The structure of the table is as follows: <table id="GridView1"> <tbody> <tr> ... </tr> <tr> ...

Exploring the functionality differences between mouse wheel tilt and scroll in JavaScript with scrollTop

Did you know that some computer mice come equipped with a scroll wheel that can tilt both left and right? This feature allows users to navigate through Google's piano roll app, which can be accessed here (source code available here). I am working to ...

Debounce function fails to properly function when the state is modified within the same function

I've been working on implementing a search-as-you-type feature and I want to debounce the function search that handles API calls. Everything works well when I only call the debounced_search function within the event handler, but I also need to update ...

What is the best way to send an email with a randomly generated HTML output using a <button>?

I am currently working on a feature where a random HTML output is sent to me via email whenever a user clicks on a button on the website page. The user receives a code when they click the button, and I want that code to be emailed to my address automatical ...

Having trouble with comparing dates on Android devices

I am struggling to compare two dates in order to categorize Browser History... Even after looking at many resources, I haven't found any helpful solutions. Here is the code I am currently using: private static String calculateDate() { SimpleDat ...

Lambda function failing to execute Auth0 methods through the Auth0 node-auth0 SDK

I am working with a lambda function that triggers when a message is added to the SQS queue. Within the message, there is a userId that I want to connect to using the Auth0 node SDK. The code snippet for my GetUserDetails function below shows that it logs ...

How can you use jQuery to target a textbox based on its value that includes quotation marks?

Dealing with a JavaScript string that includes a quote mark can cause some difficulties. For example, strings like Don't click this checkbox or He said "hi" pose unique challenges when trying to find an exact match in a checkbox value. Consider the H ...

having difficulty sorting items by tag groups in mongodb using $and and $in operators

I'm currently trying to execute this find() function: Item.find({'tags.id': { $and: [ { $in: [ '530f728706fa296e0a00000a', '5351d9df3412a38110000013' ] }, { $in: [ ...

Extracting Job Titles from LinkedIn Profiles

Currently, my code is designed to search for job titles on LinkedIn (e.g. Cyber Analyst) and gather all the links related to these job postings/pages. The goal of the code is to compile these links into a list and then iterate through them to print out th ...

When encountering an OR operator, Javascript will cease execution of the remaining conditions

This is a basic JavaScript form-validation I created. All the document.form.*.value references are present on my page, except for the document.form.dasdasdas.value ==''. In the code below, the purpose is to display an error if any of the forms a ...

Display drop-down item when selected for the first time and hide it when selected for the same item for the second time

Is there a way to display form input when "C" is selected and hide it when "A", "B", or "D" are selected? If "C" is selected again after initially showing the form input, should it be hidden? For example, if "C" is selected for the first time, the form inp ...

Ways to receive user input using the command line in Java

Currently, I am working on a code that requires user input to transform certain words into pseudo form and then perform obfuscation on the integer. I am trying to find an appropriate API to retrieve this information. Perhaps System.commands could be the so ...