Search code examples
python-3.xgoogle-chromeseleniumwebautomation

Unable to click Submit button using python-Selenium


I am trying to extract a value from google search using selenium web automation.

from selenium import webdriver
import time
import os

#open googole.com
driver = webdriver.Chrome()
time.sleep(2)
driver.get("https://www.google.co.in")

#search for bitcoin exchange rates
elem = driver.find_element_by_id("lst-ib")
elem.clear()
time.sleep(2)
elem.send_keys("bitcoin exchange rates")
time.sleep(2)
driver.find_element_by_name("btnK").click()

time.sleep(2)

#Store the value in a variable
rate = driver.find_element_by_xpath('//*[@id="rso"]/div[1]/div/div/div[2]/span[1]')

RateValue = rate.text
TodayDate = time.strftime("%x")

This works perfectly with Firefox browser. However, I am getting the following error when I run it with Chrome:

self.error_handler.check_response(response) File "C:\Users\Alauddeen\AppData\Local\Programs\Python\Python36-32\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: unknown error: Element is not clickable at point (440, 411). Other element would receive the click: ... (Session info: chrome=62.0.3202.94) (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 6.1.7601 SP1 x86)

Is there something I'm missing here? Any help is appreciated.

Thanks!


Solution

  • There is probably a search suggestion box on top of the btnK, hiding it from sight so it can’t be clicked.

    Use something like

    elem.send_keys(Keys.ENTER)
    

    Or

    elem.send_keys(Keys.ESCAPE)
    

    after sending your search text to the input to make the suggestion box go away.