To get this to work, add one extra step of clicking the element before sending the keys:
datefield = driver.find_element_by_id('ctl00_cphMain_SrchDates1_txtFiledFrom')
datefield.click()
datefield.send_keys("01012011")
Update:
It looks like you might have to use ActionChains
after all in your case, which will allow you to chain a series of actions together, and then perform them one after the other:
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome()
driver.get("https://cotthosting.com/NYRocklandExternal/User/Login.aspx")
driver.find_element_by_id('ctl00_cphMain_blkLogin_btnGuestLogin').click()
driver.find_element_by_id('ctl00_cphMain_SrchNames1_txtFirmSurName').send_keys("Adam")
datefield = driver.find_element_by_id('ctl00_cphMain_SrchDates1_txtFiledFrom')
ActionChains(driver).move_to_element(datefield).click().send_keys('01012011').perform()
search_btn = driver.find_element_by_id('ctl00_cphMain_btnSearchAll')
ActionChains(driver).move_to_element(search_btn).click().click().perform()
I am not sure why two click()
calls were necessary in this case, but it seems that they were. I tried a few other things including double_click()
, but this was the only thing that worked for me to get the datefield unfocused and then click the search button.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…