5

In my python code, I want to input a date in the Date textbox. However, the existing date cannot be cleared, and a date cannot be entered either. I am using Selenium. I think the element is found, but anyway the Send_keys() function does not work on this textbox. What is the problem?

Thanks.

url = 'https://iol1.iroquois.com/infopost/Pages/OperationallyAvailable.php?parentId=100'
browser.get(url)
date_element = browser.find_element_by_id('searchDateTextfield-inputEl')
date_element.click()
date_element..clear()
date_element.send_keys(slash_date)
date_element.submit()
2
  • also, from selenium import webdriver Commented Oct 22, 2015 at 18:16
  • You need to just send numbers for the date (no slashes, etc.). If you manually type in the box, it doesn't accept anything but numbers as far as I've seen. Commented Oct 22, 2015 at 22:50

2 Answers 2

4

Below is the full-functional code-

import time
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
browser = webdriver.Firefox()

url = 'https://iol1.iroquois.com/infopost/Pages/OperationallyAvailable.php?parentId=100'
browser.get(url)
WebDriverWait(browser,10000).until(EC.visibility_of_element_located((By.TAG_NAME,'body')))
date_element = browser.find_element_by_id('searchDateTextfield-inputEl')
date_element.click()
date_element.send_keys(Keys.HOME)

# For date 10 Oct 2015
date_element.send_keys("10042015")
date_element.send_keys(Keys.TAB)
browser.find_element_by_xpath("//span[@id='retrieveButton-btnInnerEl']").click()
time.sleep(100)
browser.close()
Sign up to request clarification or add additional context in comments.

Comments

2

This worked for me. Just type in the date without any symbols, just numbers.

...
from selenium.webdriver.common.keys import Keys

date_element = browser.find_element_by_id('searchDateTextfield-inputEl')
date_element.click()
date_element.send_keys(Keys.HOME)

# For date 23/10/2015 the format should be MMddyyyy
date_element.send_keys("10232015")
...

5 Comments

You don't really need the .click() and send_keys(Keys.HOME) but I needed a wait.
I tried it with an implicit wait for 30 seconds. But it still didn't work for me. But once I added the click() and send_keys() function code, it worked smoothly. I was using Firefox-webdriver (if that makes any difference).
That's strange... I'm also using the FF driver.
Your answer is also great. Using date_element.send_keys(Keys.HOME) is critical for my code; now it works.
JRodDynamite's comment worked for me. Unfortunately, I accidentally removed my upvote and SO is a bit unforgiving. Anyway, all I needed to add before my send_keys() was click()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.