0

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

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Datajack
  • 88
  • 3
  • 16

1 Answers1

1

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.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
f-starace
  • 278
  • 1
  • 17
  • You seem to be right. But what exactly do I need to execute with driver.execute_script to set the date? I don't know JavaScript very well... :( – Datajack Aug 29 '21 at 07:29
  • did not work, got this exception selenium.common.exceptions.JavascriptException: Message: javascript error: window.querySelector is not a function – cruisepandey Aug 29 '21 at 07:37
  • Yeah sorry. I'm testing it now. It should have been document, my bad :) – f-starace Aug 29 '21 at 07:37
  • It still not working for me when I pass this `dob = "02-01-1990"`, it fills `-1989` in the input field. Certainly there's no error cause it fills something but it fills `-1989` any idea why ? – cruisepandey Aug 29 '21 at 08:43
  • Unfortunately by passing your date in the console on the website I could not replicate your problem: `document.querySelector('input[name=signup_dob]').value = '02-01-1990'` displays correctly `"02-01-1990"` Can you share the relevant bit of code? – f-starace Aug 29 '21 at 09:04