Mistake in code mm = driver.find_element_by_xpath('//*[@id="{}"]'.format(month))
. You find first element in DOM(which combined with element data
instead data2
) and it is not visible yet.
There is workig code
mm = driver.find_element_by_id('date2').find_element_by_class_name('months-view').find_element_by_id(month)
mm.click()
Also good deal, to use WebDriverWait, because the site is very slow.
for example
to_date = WebDriverWait(driver, 10).until(
expected_conditions.presence_of_element_located(
(By.XPATH, '//*[@id="date2"]/angular2-date-picker/div/div[1]/i')))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…