Search code examples
pythonselenium-webdriver

Unable to send keys to text box using Selenium. Getting selenium.common.exceptions.TimeoutException: Message:


I am trying to send keys to the search bar text box using Selenium but getting the error:

Traceback (most recent call last):
  File ".\test.py", line 19, in <module>
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#typeahead-input-56352"))).send_keys("2216 NW 6 PL FORT LAUDERDALE")
  File "D:\Python Projects\Title Search\titlesearch\lib\site-packages\selenium\webdriver\support\wait.py", line 95, in 
until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
Stacktrace:
        GetHandleVerifier [0x00007FF6D9C9AD02+56930]
        (No symbol) [0x00007FF6D9C0F602]
        (No symbol) [0x00007FF6D9AC42E5]
        (No symbol) [0x00007FF6D9B098ED]
        (No symbol) [0x00007FF6D9B09A2C]
        (No symbol) [0x00007FF6D9B4A967]
        (No symbol) [0x00007FF6D9B2BCDF]
        (No symbol) [0x00007FF6D9B481E2]
        (No symbol) [0x00007FF6D9B2BA43]
        (No symbol) [0x00007FF6D9AFD438]
        (No symbol) [0x00007FF6D9AFE4D1]
        GetHandleVerifier [0x00007FF6DA016F8D+3711213]
        GetHandleVerifier [0x00007FF6DA0704CD+4077101]
        GetHandleVerifier [0x00007FF6DA06865F+4044735]
        GetHandleVerifier [0x00007FF6D9D39736+706710]
        (No symbol) [0x00007FF6D9C1B8DF]
        (No symbol) [0x00007FF6D9C16AC4]
        (No symbol) [0x00007FF6D9C16C1C]
        (No symbol) [0x00007FF6D9C068D4]
        BaseThreadInitThunk [0x00007FFD02F37344+20]
        RtlUserThreadStart [0x00007FFD03F226B1+33]

My code that I am using for sending the keys:

# Import Dependencies
from bs4 import BeautifulSoup as bs
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import time

options = webdriver.ChromeOptions()
options.headless = True

driver = webdriver.Chrome()
driver.maximize_window()

driver.get("https://broward.county-taxes.com/public/search/property_tax")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@class="svg-icon"]'))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#typeahead-input-56352"))).send_keys("2216 NW 6 PL FORT LAUDERDALE")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="search-icon"]/svg'))).click()

I am even closing a pop-up before sending the keys. I have used XPATH, CSS_SELECTOR both. And both seems to be getting the same error.

Please help.


Solution

  • Root cause of the issue: The value of ID attribute is dynamic. So, input#typeahead-input-56352 this won't work. Each time page loads the number(56352) changes.

    Solution: You can use XPath locator strategy instead, and XPath expression can be: //input[@role='searchbox']

    Change below line:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#typeahead-input-56352"))).send_keys("2216 NW 6 PL FORT LAUDERDALE")
    

    To:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@role='searchbox']"))).send_keys("2216 NW 6 PL FORT LAUDERDALE")
    

    Note: Also, in the following line, this XPath expression //*[@id="search-icon"]/svg is incorrect, it's not locating any element. I have fixed it in the below working code.

    Check the refactored and working code below:

    driver = webdriver.Chrome()
    driver.maximize_window()
    wait = WebDriverWait(driver, 20)
    
    driver.get("https://broward.county-taxes.com/public/search/property_tax")
    wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@class="svg-icon"]'))).click()
    wait.until(EC.element_to_be_clickable((By.XPATH, '//input[@role="searchbox"]'))).send_keys("2216 NW 6 PL FORT LAUDERDALE")
    wait.until(EC.element_to_be_clickable((By.XPATH, '//span[@id="search-icon"]'))).click()