1

Hi I am trying to figure out how to do date picking on the calendar for zacks for some personal project. unable to figure out how that works. I read a post on datepickers being used as a table and i can try that approach but i want to get date picking for future and past and on the page, only the current month shows up so would ideally like to see the onclick functionality working.

chromedriver = "/usr/bin/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
driver.get('https://www.zacks.com/earnings/earnings-calendar')
driver.maximize_window()
print('page load waiting ......')
time.sleep(5)
date_field = driver.find_element_by_id('earnings_calendar_events').find_element_by_id('date_select')
date_field.click() # opens up the calendar
time.sleep(2)
print('sending key 3')
date_field.send_keys('12/1/2020') #send keys doesn't work.
time.sleep(5)
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Sam Thadhani
  • 585
  • 1
  • 10
  • 21

1 Answers1

2

To select the date 12/1/2020 within the website https://www.zacks.com/earnings/earnings-calendar you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    driver.get('https://www.zacks.com/earnings/earnings-calendar')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a#date_select img"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "table.sb_minicalview td > span#dt_1"))).click()
    
  • Using XPATH:

    driver.get('https://www.zacks.com/earnings/earnings-calendar')
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@id='date_select']/img"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//table[@class='sb_minicalview']//td/span[@id='dt_1']"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • Browser Snapshot:

zacks_datepicker


References

You can find a couple of relevant detailed discussion in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks, this does work but i also want to be able to go back in last month like Nov and be able to get the data for lets say 5th of Nov or something like that. With this approach, i can only get data for the current month. I was thinking of going into table as mentioned in the post but this approach limits me to current month. – Sam Thadhani Dec 05 '20 at 04:46
  • That sounds to be all together a different requirement. Can you raise a new question as per your new requirements? Stackoverflow volunteers will be happy to help you out. – undetected Selenium Dec 05 '20 at 07:44
  • happy to accept the answer buddy but i the original question states that i want to pick up past and future dates and as i said in the question, i can definitely do traversing on the table but this only gives me data for the current month. – Sam Thadhani Dec 06 '20 at 01:06
  • i think i can do that by just clicking the previous month and traversing that afterwards and similarly for future month as well. – Sam Thadhani Dec 06 '20 at 01:10