TestProject Forum
Powered by leading experts in the test automation community

Typing dates in text fields in Firefox

I’m trying to automate a test that involves typing a date in a text field (mdc-text-field__input). The text field is formatted to only accept dates in the mm/dd/yyyy format. Right now, typing ‘12122025’ will enter the date just fine in Chrome. However, in Firefox, the sample ‘mm’ text is highlighted, and nothing else happens. The test fails shortly after since the entered info cannot be save.

Is there a reason for the date not being typed? Is there another way to enter text in TestProject? Is there something additional that has to be done to enter dates in Firefox? Is there an addon for working with Firefox, perhaps? Any help or pointers are appreciated.

The included screenshot is from the failed test in Firefox.

FirefoxDateFailure

Hi @jbauer,

Thanks for reaching out!
Can you please elaborate about what happens when you trying to type the text in Firefox? It’s not typing anything in the textbox?

Another possible solution is to interact with the date picker element instead of typing text. You can create 2 elements:

  1. Day - for example, you can create a dynamic XPath that will get the day number as an input parameter: //div[. = ‘DAY_NUM’]. The DAY_NUM will be a parameter.

  2. Month and Year can be taken from the combobox using type text on it.

Let me know if it helped :slight_smile:

Kind reagards,
Amit

That is correct. There is a sample text of mm/dd/yyyy in the text box. The clear command does not remove the sample text. The type command does not type the desired text. The only thing that happens is the ‘mm’ section of the sample text is highlighted. This is only in Firefox. The type command works fine in Chrome.

With the dynamic XPath option, would that mean that I’m not interacting with the text box, but actually trying to interact with the calendar object and dynamically select a date currently displayed? What if the date was from a different year, or some other time not currently displayed? Or is the dynamic XPath somehow able to enter data directly into the field?

Hi @jbauer,

You can try to clear the content with the “Execute JavaScript” action. Write a simply JavaScript command that will clear the content of the date field.

As for your other question, when you create a dynamic element in the recorder, you are combining a parameter in it. It means that you can change the value before or even during the test execution.
So, if any attribute changes (e.g. day, month or year), you will change the value accordingly.

I finally figured out what was happening. Since the text field has the parameter “date”, Firefox requires automated testing software to enter the info as a date in the correct format. For Firefox, that’s yyyy-mm-dd. Since the sample text is set as mm/dd/yyyy, I was entering it in that format. When I changed the keyboard input to yyyy-mm-dd, the text was typed, and it was even displayed in the correct mm-dd-yyyy format on the website. However, that test now breaks in Chrome, since it enters it as yy-yy-mmdd, so it looks like we’ll need two separate jobs to test calendar entries.

Source: https://github.com/mozilla/geckodriver/issues/1070

Hi @jbauer,

I’m really glad that you figured this out!
To overcome this issue, you can try to use one of the two format and define a recovery test on that step. This recovery test, will try to use the other date format. That way, your test won’t break on different browsers.