本文介绍了Python Selenium:输入文本框,send_keys 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 python 代码中,我想在日期文本框中输入一个日期.但是,不能清除现有日期,也不能输入日期.我正在使用硒.我认为该元素已找到,但无论如何 Send_keys() 函数在此文本框上不起作用.问题是什么?

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?

谢谢.

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()

推荐答案

以下是全功能代码-

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()

这篇关于Python Selenium:输入文本框,send_keys 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 01:28