Datajack
Datajack

Reputation: 190

Filling date field with Selenium WebDriver

I am trying to fill out a registration form using Selenium for practice as I am beginning to familiarize myself with this library.

It is the registration form on this website: https://www.fast2sms.com/

What I am currently trying

I start with this:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://www.fast2sms.com/")

Over there, I click on the signup button with the data-target attribute set to "#signupM" using a css selector for the same:

driver.find_element_by_css_selector('button[data-target="#signupM"]').click()

I then set up some dummy values for the fields:

from phone_gen import PhoneNumber

name = "John Doe"
dob = "02-01-1990"
phone_number = PhoneNumber("India").get_number().replace("+91", "")
email_address = f"{phone_number}@mailinator.com"

I wait for the name field, and fill it:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

name_field = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'input[name="signup_name"]')))
name_field.send_keys(name)

Then phone number and email address:

phone_number_field = driver.find_element_by_css_selector('input[name="signup_mobile"]')
phone_number_field.send_keys(phone_number)

email_addr_field = driver.find_element_by_css_selector('input[name="signup_email"]')
email_addr_field.send_keys(email_address)

Everything up until here works fine, exactly as expected, but when I try to fill in the Date of Birth field, I face issues:

dob_field = driver.find_element_by_css_selector('input[name="signup_dob"]')
dob_field.send_keys(dob)

Issues I face

  1. Date of birth field is not filled.
  2. It throws an error, selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
  3. I am unable to submit the form with date of birth not filled.

Ways I have tried to debug

  1. Rechecked the CSS Selector
  2. Waited for the data-of-birth field to be interactable using WebDriverWait
  3. Instead of filling in the text, I tried interacting with the popup that shows up when I click the field (I think I have to do this, but don't know how.)

Questions which may seem like duplicates but are not:

Select Particular Date using Python Selenium (Rollover dates)

Using Selenium on calendar date picker

Interacting with pop-up boxes using selenium in python

Upvotes: 0

Views: 1549

Answers (1)

f-starace
f-starace

Reputation: 288

I get why it may not be working. The website is using a particular javascript library called datedropper. Thus the input element for the date is in the readonly format.

I think you can resolve it by doing:

js_code = "document.querySelector('input[name=signup_dob]').value =" 
driver.execute_script(js_code + your_date)

Not quite sure the js code is gonna work. It might need some editing.

Upvotes: 1

Related Questions