1

I am attempting to choose date on a calendar on this website. On the first calendar (date from) I can choose the desired date using Selenium, however, I get the following error while clicking on the desired month even though the exact element is found.

ElementNotInteractableException:element not interactable

To me, it seems weird because I can click on the month manually. Here is what I have tried so far

from selenium import webdriver
import time

year = 2019
month = 'JAN'
driver_path = 'pathtochromedriver\chromedriver.exe'
url = 'https://app.cpcbccr.com/ccr/#/caaqm-dashboard-all/caaqm-landing/data'
driver = webdriver.Chrome(driver_path)
driver.get(url)
time.sleep(8)

# find desired calendar
to_date = driver.find_element_by_xpath('//*[@id="date2"]/angular2-date-picker/div/div[1]/i')
to_date.click()
# Click on year dropdown
to_year = driver.find_element_by_xpath('//*[@id="date2"]/angular2-date-picker/div/div[2]/div[3]/div')
to_year.click()

driver.find_element_by_xpath('//*[@id="{}"]'.format(year)).click()
# Click on month dropdown
to_month = driver.find_element_by_xpath('//*[@id="date2"]/angular2-date-picker/div/div[2]/div[2]/div')
to_month.click()
mm = driver.find_element_by_xpath('//*[@id="{}"]'.format(month))
mm.click()
Vinod Kumar
  • 1,383
  • 1
  • 12
  • 26

1 Answers1

2

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'))) 
  • Thanks a lot for fixing the issue for me. Indeed the website is super slow and Webdriverwait will be a nice idea. – Vinod Kumar Nov 03 '20 at 16:28