Python Selenium Path not found

I have wrote the code

import os
from webdriver_manager.chrome import ChromeDriverManager
import time

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

options = Options()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--start-maximized')
options.page_load_strategy = 'eager'
driver = webdriver.Chrome(options=options)
url = "https://www.moneycontrol.com/india/stockpricequote/chemicals/tatachemicals/TC"
driver.get(url)
try:
    wait = WebDriverWait(driver, 10)
except Exception:
driver.send_keys(Keys.CONTROL +'Escape')
driver.find_element_by_link_text("Bonus").click()
try:
    wait = WebDriverWait(driver, 5)
except Exception:
    driver.send_keys(Keys.CONTROL +'Escape')
for i in range(0, 50):
    bonus_month = driver.find_element_by_xpath ("//*[@class= 'mctable1.thborder.frtab']/tbody/tr[%s]/td[1]"%(i)) 
    print(bonus_month.text)
    bonus = driver.find_element_by_xpath ("//*[@class= 'mctable1.thborder.frtab']/tbody/tr[%s]/td[1]"%(i)) 
    print(bonus.text)

This gives me error

no such element: Unable to locate element: {"method":"xpath","selector":"//*[@class= 'mctable1.thborder.frtab']/tbody/tr[0]/td[1]"}

Element on the page: enter image description here

Where I am making mistake in finding Exbonus and Ratio?

Answer

First use the clickable method from the expected conditions to check that the element is clickable within given time to just make sure it is operational.

Once the click action performed on the bonus link the table takes some time to finishes loading. In meantime selenium tries to fetch the table content and fails to get it. So again add wait for the element to load and then grab the table using Xpath and iterate over the rows of the table. –

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//ul[@id='corporation_tab']//a[@href='#ca_bonus']")))

driver.find_element_by_link_text("Bonus").click()

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//tbody[@id='id_b']/tr")))

tableRows = driver.find_elements_by_xpath('//tbody[@id="id_b"]/tr')
print(tableRows)
for i in tableRows:
    AnnouncementDate = i.find_element_by_xpath('td[1]').text
    exbonus = i.find_element_by_xpath('td[2]').text
    ratio = i.find_element_by_xpath('td[3]').text

    print(AnnouncementDate + " tt " + exbonus + " tt " + ratio)

This returns me the output –

enter image description here

You will need following extra import –

from selenium.webdriver.support import expected_conditions as EC