Selenium -  Message: unknown error: Element is not clickable at point(x,y)

SQL Guru
SQL Guru used Ask the Experts™
on
Below code was working few days back ago.But suddenly i'm experience this error. I tried implicit,explicit wait, time.sleep but nothing is working out.  I have also verified that element are present.I have checked similar error in stackoverflow , where they have mentioned to use explicit wait. As I mentioned earlier, it's doesn't work. Am I new to selenium , so kindly help me on this issue.

Error code :
driver.find_element_by_xpath("//*[@id='wrapper']/main/div/p[5]/a").click()

Open in new window

Complete code for the  perusal.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
import datetime 
import time 
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from bs4 import BeautifulSoup
from IPython.display import clear_output

def select_elements(system,yy,mm,dd,hr,mins,meridiem):
    select = Select(driver.find_element_by_id('fin_compatibility_system'))
    select.select_by_value(system)

    select = Select(driver.find_element_by_id('fin_gyear'))
    select.select_by_value(yy)

    select = Select(driver.find_element_by_id('fin_gmonth'))
    select.select_by_value(mm)

    select = Select(driver.find_element_by_id('fin_gday'))
    select.select_by_value(dd)

    select = Select(driver.find_element_by_id('fin_ghour'))
    select.select_by_value(hr)

    select = Select(driver.find_element_by_id('fin_gmin'))
    select.select_by_value(mins)

    select = Select(driver.find_element_by_id('fin_gapm'))
    select.select_by_value(meridiem)


    #################################################################################


    select = Select(driver.find_element_by_id('fin_byear'))
    select.select_by_value('1986')

    select = Select(driver.find_element_by_id('fin_bmonth'))
    select.select_by_value('6')

    select = Select(driver.find_element_by_id('fin_bday'))
    select.select_by_value('4')

    select = Select(driver.find_element_by_id('fin_bday'))
    select.select_by_value('4')

    select = Select(driver.find_element_by_id('fin_bhour'))
    select.select_by_value('1')

    select = Select(driver.find_element_by_id('fin_bmin'))
    select.select_by_value('49')

    select = Select(driver.find_element_by_id('fin_bapm'))
    select.select_by_value('pm')


yy = 1990
file_name = 'astro_time_'+str(yy)+'.txt'
next_year = yy +1 
######################################################################################
check_min = 120
mm = 8
dd = 19
hr = 12
mins = 0 
sec = 0 
retries = 0 

calc_date = datetime.datetime(yy, mm, dd, hr, mins, sec, 0)

driver = webdriver.Chrome('C:\\Users\\Vivekanandhan\\Downloads\\Compressed\\chromedriver_win32\\chromedriver.exe')
while (calc_date.year < next_year):
    try:
        if (retries >= 10 ):
            break
        
        yy =  str(calc_date.year )
        mm = str(calc_date.month)
        dd = str(calc_date.day)
        if (calc_date.hour ==0):
            hr  = str(12)
        elif(calc_date.hour > 12):
            hr  =str(calc_date.hour-12)
        else:
            hr = str(calc_date.hour)
        mins = str(calc_date.minute)

        if (calc_date.hour >= 12 ): 
            meridiem = 'pm'
        else :
            meridiem = 'am'

        calc_date = calc_date + datetime.timedelta(minutes = check_min) 
        ########################################################################################################
        
        driver.get('http://www.prokerala.com/astrology/porutham/')
        system = 'kerala'
        select_elements(system,yy,mm,dd,hr,mins,meridiem)
        time.sleep(1.0)
        driver.find_element_by_xpath("//*[@id='astro-submit-button']").click()

        k_compatibility = driver.find_element_by_xpath("//*[@id='wrapper']/main/div/div[1]/div/h2/span").text
        girl_Nakshatra = driver.find_element_by_xpath("//*[@id='wrapper']/main/div/div[1]/table/tbody/tr[1]/td[1]/a").text
        boy_Nakshatra = driver.find_element_by_xpath("//*[@id='wrapper']/main/div/div[1]/table/tbody/tr[1]/td[2]/a").text

        girl_rasi = driver.find_element_by_xpath("//*[@id='wrapper']/main/div/div[1]/table/tbody/tr[2]/td[1]/a").text
        boy_rasi = driver.find_element_by_xpath("//*[@id='wrapper']/main/div/div[1]/table/tbody/tr[2]/td[2]/a").text

        k_papasamyam = driver.find_element_by_xpath("//*[@id='wrapper']/main/div/div[10]/p/strong").text

        driver.find_element_by_xpath("//*[@id='wrapper']/main/div/p[5]/a").click()
        
        #############################################################################################################
        system = 'tamil' 
        select_elements(system,yy,mm,dd,hr,mins,meridiem)
        time.sleep(1.0)
        driver.find_element_by_xpath("//*[@id='astro-submit-button']").click()

        t_compatibility  = driver.find_element_by_xpath("//*[@id='wrapper']/main/div/div[1]/div/h2/span").text
        t_papasamyam = driver.find_element_by_xpath("//*[@id='wrapper']/main/div/div[10]/p/strong").text
        ##############################################################################################################
        driver.find_element_by_xpath("//*[@id='wrapper']/main/div/form/input[19]").click()

        kundlis_points = driver.find_element_by_xpath("//*[@id='wrapper']/main/div/div[5]/table/tbody/tr[9]/td[3]/h2").text
        kundlis_remarks = driver.find_element_by_xpath("//*[@id='wrapper']/main/div/div[6]/div[5]/h2").text
        ################################################################################################################
        driver.refresh()
        date = dd + "/"+  mm +"/" +yy +" " +hr +":" +mins+" "+meridiem 
        text = str(dd +   mm +yy  +hr +mins +meridiem +";"+
               dd + "/"+  mm +"/" +yy +";"+
               hr +":" +mins+" "+meridiem +";"+

               boy_Nakshatra +";"+
               girl_Nakshatra +";"+

               boy_rasi +";"+
               girl_rasi  +";"+

               k_compatibility +";"+
               k_papasamyam +";"+

               t_compatibility +";"+
               t_papasamyam +";"+

               kundlis_points +";"+
               kundlis_remarks+";")

        with open(file_name, "a") as myfile:
            myfile.write("\n" + text)
            retries = 0 
        raise TypeError("Oups!") 
    except Exception as e:
        retries+=1
        clear_output(wait=True)
        print (str (time.strftime("%Y-%m-%d %H:%M")) + " " + "retries" +":" + str(retries)+ " Error : " + str(e))
        calc_date = calc_date - datetime.timedelta(minutes = check_min) 
        driver.refresh()
        pass

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
for the submit buttons, I found that a call to scrollIntoView followed by a submit was enough
	e = driver.find_element_by_xpath("//*[@id='astro-submit-button']")
	driver.execute_script("arguments[0].scrollIntoView(true);", e)
	e.submit()

# and

	e = driver.find_element_by_xpath("//*[@id='wrapper']/main/div/form/input[19]")
	driver.execute_script("arguments[0].scrollIntoView(true);", e)
	e.submit()

Open in new window


for the "a" element, I found I needed an extra scrollBy
	e = driver.find_element_by_xpath("//*[@id='wrapper']/main/div/p[5]/a")
	driver.execute_script("arguments[0].scrollIntoView(true);", e)
	driver.execute_script("window.scrollBy(0,-250)", "")
	e.click()

Open in new window


I quit when I got "TypeError: Oups!"

Author

Commented:
Thanks alot, worked like a charm.
Since I'm new to selenium , I'm perplexed. Before the code was working absolutely fine but now it started to fail. Why are we using execute script and scrollIntoView method? cannot we achieve the same functionality  by just using a click() method? On which scenarios, do we oblige  to above methods?
Before the code was working absolutely fine but now it started to fail.
perhaps the page authors slightly changed something which is a real concern when using Selenium or any other web-scraping solution
Why are we using execute script and scrollIntoView method?
we use scrollIntoView to make sure that the element we want clicked is in the viewport.
apparently, Selenium does not allow clicking on elements that are not visible hence your error
Element is not clickable at point(x,y)
BTW, you've been doing a few things with Selenium. Perhaps a better approach would be to ask the page authors if they have an API you can use instead. That way, you won't be at the mercy of even minor changes to the web pages.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial