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()
sendKeys() not working in Selenium Webdriver If we encounter issues while working with the sendKeys method, then we can use the JavaScript Executor to input text within an edit box. Selenium can run JavaScript commands with the help of the executeScript method.
We can send keyboard input to a textbox on a webpage in Selenium webdriver in Python using the method send_keys. The text to be entered is passed as a parameter to that method. To perform keyboard actions, we can also use the send_keys method and then pass the class Keys.
send_keys method is used to send text to any field, such as input field of a form or even to anchor tag paragraph, etc. It replaces its contents on the webpage in your browser. Also note, it is possible to call send_keys on any element, which makes it possible to test keyboard shortcuts such as those used on Gmail.
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()
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")
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With