Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Selenium: input textbox, send_keys not working

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()
like image 449
TomQuin Avatar asked Oct 22 '15 18:10

TomQuin


People also ask

Why sendKeys is not working in selenium Python?

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.

How do I fill a textbox in selenium Python?

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.

How can the send_ keys Function be used?

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.


2 Answers

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()
like image 192
SIslam Avatar answered Oct 26 '22 01:10

SIslam


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")
...
like image 21
JRodDynamite Avatar answered Oct 26 '22 00:10

JRodDynamite