如何使用 selenium 处理和选择弹出/隐藏表单/表格中的元素?

我想使用 selenium 从以下网站选择弹出日期表/日历。我试图在其中添加双击功能,但未能选择我想要的日期。


from selenium.webdriver.common.action_chains import ActionChains

ccass = driver.get('http://www.hkexnews.hk/sdw/search/searchsdw_c.aspx')

ticker = '00001'

menu = driver.find_element_by_xpath("#date-picker-popup").click()

ccass_search_year = driver.find_element_by_xpath('//*[@id="date-picker"]/div[1]/b[1]/ul/li[2]/button').click()

actions.double_click(ccass_search_year)

ccass_search_month = driver.find_element_by_xpath('//*[@id="date-picker"]/div[1]/b[2]/ul/li[4]/button').click()

actions.double_click(ccass_search_month)

ccass_search_day =  driver.find_element_by_xpath('//*[@id="date-picker"]/div[1]/b[3]/ul/li[4]/button').click()

actions.double_click(ccass_search_day)

ccass_search = driver.find_element_by_xpath('//*[@id="txtStockCode"]').send_keys(ticker) #Keys.ENTER) 

ccass_search_click = driver.find_element_by_xpath('//*[@id="btnSearch"]').click()


炎炎设计
浏览 306回答 2
2回答

精慕HU

我编辑了一点,问题是虽然我从弹出的日期选择器中找到了所有这些按钮,但我无法获得我选择的日期的结果:  year = year_list['2019']  month = month_list['4']  day = day_list['4']  year_list = {'2018':'//*[@id="date-picker"]/div[1]/b[1]/ul/li[1]/button', '2019':'//*[@id="date-picker"]/div[1]/b[1]/ul/li[2]/button'}  month_list = {'1':'//*[@id="date-picker"]/div[1]/b[2]/ul/li[1]/button', '2':'//*[@id="date-picker"]/div[1]/b[2]/ul/li[2]/button', '3':'//*[@id="date-picker"]/div[1]/b[2]/ul/li[3]/button', '4':'//*[@id="date-picker"]/div[1]/b[2]/ul/li[4]/button', '5':'//*[@id="date-picker"]/div[1]/b[2]/ul/li[5]/button', '6':'//*[@id="date-picker"]/div[1]/b[2]/ul/li[6]/button', '7':'//*[@id="date-picker"]/div[1]/b[2]/ul/li[7]/button', '8':'//*[@id="date-picker"]/div[1]/b[2]/ul/li[8]/button', '9':'//*[@id="date-picker"]/div[1]/b[2]/ul/li[9]/button', '10':'//*[@id="date-picker"]/div[1]/b[2]/ul/li[10]/button', '11':'//*[@id="date-picker"]/div[1]/b[2]/ul/li[11]/button', '12':'//*[@id="date-picker"]/div[1]/b[2]/ul/li[12]/button'}  day_list = {'1':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[1]/button','2':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[2]/button','3':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[3]/button','4':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[4]/button','5':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[5]/button','6':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[6]/button','7':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[7]/button','8':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[8]/button','9':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[9]/button','10':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[10]/button','11':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[11]/button','12':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[12]/button','13':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[13]/button','14':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[14]/button','15':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[15]/button','16':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[16]/button','17':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[17]/button','18':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[18]/button','19':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[19]/button','20':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[20]/button','21':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[21]/button','22':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[22]/button','23':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[23]/button','24':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[24]/button','25':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[25]/button','26':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[26]/button','27':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[27]/button','28':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[28]/button','29':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[29]/button','30':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[30]/button','31':' //*[@id="date-picker"]/div[1]/b[3]/ul/li[31]/button'}  ccass = driver.get('http://www.hkexnews.hk/sdw/search/searchsdw_c.aspx')  popup_datepicker = driver.find_element_by_xpath('//*[@id="txtShareholdingDate"]').click()  ccass_search_year = driver.find_element_by_xpath(year).click()  actions.double_click(ccass_search_year)  ccass_search_month = driver.find_element_by_xpath(month).click()  actions.double_click(ccass_search_month)  ccass_search_day = driver.find_element_by_xpath(day).click()  actions.double_click(ccass_search_day)  ccass_search = driver.find_element_by_xpath('//*[@id="txtStockCode"]').send_keys(ticker) #Keys.ENTER)   ccass_search_click = river.find_element_by_xpath('//*[@id="btnSearch"]').click()

暮色呼如

您尝试选择的日期已禁用。您不能选择3rd April 2018。您只能从 4 月 10 日开始选择,我猜它明天将被禁用。对不起,你来晚了。其中禁用日期的类名称也。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python