在日历日期选择器上使用硒 [英] Using selenium on calendar date picker

查看:87
本文介绍了在日历日期选择器上使用硒的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从此页面上的日历中选择日期(01/01/2011)。 https://cotthosting.com/NYRocklandExternal/LandRecords/protected/SrchQuickName.aspx

I am trying to pick a date (01/01/2011) from a calendar on this page. https://cotthosting.com/NYRocklandExternal/LandRecords/protected/SrchQuickName.aspx

日历在表单上显示 Date:FROM 的一部分。当我单击它时,会弹出一个日历供您选择日期。但是,该字段还允许您输入日期。考虑到日历的复杂性,我选择使用 send_keys(),但是它不起作用。

The calendar is on the part of the form that says Date: FROM. When I click it, a calendar pops up for you to pick dates. However, the field also allows you type in a date. Given the complexity of calendars, I have chosen to use send_keys() but it is not working.

我有通过其ID标识了空字段日期字段,但由于某种原因,它没有填写表格。当我尝试时:

I have identified the empty field date field by its ID but for some reason it does not fill the form. when I try:

driver.find_element_by_id('ctl00_cphMain_SrchDates1_txtFiledFrom').send_keys("01012011")

关于如何进行不同操纵的任何想法?我正在将Python 2.7与Selenium和ChromeDriver一起使用

Any ideas on how I can maneuver it differently? I'm using Python 2.7 with Selenium and ChromeDriver

推荐答案

要使其正常工作,请在单击该元素之前增加一个额外的步骤发送密钥:

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



更新:



您似乎必须使用 ActionChains 毕竟,这将允许您将一系列动作链接在一起,然后一个接一个地执行:

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

我不确定在这种情况下为什么需要两个 click()调用,但是看来确实如此。我尝试了其他一些操作,包括 double_click(),但这是唯一使我不关注日期字段然后单击搜索按钮的方法。

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.

这篇关于在日历日期选择器上使用硒的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆