3

Im trying to search for stock on www.finanzen.net using selenium but always get

ElementNotInteractableException: element not interactable

from selenium import webdriver

import time

chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs", prefs)
chrome_options.add_argument("start-maximized")
driver = webdriver.Chrome(options=chrome_options, executable_path=r'F:\chromedriver.exe')

driver.get('https://www.finanzen.net/')
time.sleep(5)
cookie_banner_button = driver.find_element_by_xpath("//button[@onclick='cookieBannerOverlayClick();']")
cookie_banner_button.click()

search_field = driver.find_element_by_xpath("//input[@class='search-input']")


#search_field.click()
search_field.send_keys('bmw')
search_field.submit()
time.sleep(5)
driver.quit()

HTML:

html-code of element

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

1

The xpath that you have used are pointing to two elements and first element on which it is pointing is not interactable due to which you are getting the exception.
Have found the correct xpath for the element, please refer to the code below:

from selenium import webdriver

import time

chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs", prefs)
chrome_options.add_argument("start-maximized")
driver = webdriver.Chrome(options=chrome_options, 
executable_path=r'F:\chromedriver.exe')

driver.get('https://www.finanzen.net/')
time.sleep(5)
cookie_banner_button = driver.find_element_by_xpath("//button[@onclick='cookieBannerOverlayClick();']")
cookie_banner_button.click()

search_field = driver.find_element_by_xpath("//div[@class='shadow']//input[@class='search-input']")
search_field.send_keys('bmw')
search_field.submit()
time.sleep(5)
driver.quit()
Sameer Arora
  • 4,439
  • 3
  • 10
  • 20
1

To search for stock on www.finanzen.net 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.finanzen.net/')
    submit_button = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "form[name='mmssearch'] div.search-group>input.search-input[name='_search']")))
    submit_button.send_keys('bmw')
    submit_button.submit()
    
  • Using XPATH:

    driver.get('https://www.finanzen.net/')
    submit_button = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//form[@name='mmssearch']//div[@class='search-group']/input[@class='search-input' and @name='_search']")))
    submit_button.send_keys('bmw')
    submit_button.submit()
    
  • 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:

finanzen

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352