-1
from selenium import webdriver
from bs4 import BeautifulSoup
from openpyxl import load_workbook
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import pandas as pd 
from pandas import ExcelWriter

driver = webdriver.Chrome('./chromedriver')
driver.implicitly_wait(5)
driver.get('http://car.bitauto.com/')

# step 2
elem = driver.find_element_by_id('cx-searchBox')
elem.click()

wait = WebDriverWait(driver, 10)
brandlist = [brand.text for brand in wait.until(EC.visibility_of_all_elements_located((By.CLASS_NAME, 'yccmp-brand-item ')))]
brands2 = ["".join(brand[1:].lstrip()) for brand in brandlist]


for brand in brands2:
    driver.get('http://car.bitauto.com/')
    elem = driver.find_element_by_id('cx-searchBox')
    elem.click()  
    elem.send_keys(brand)
    # The error occurs at this part

    driver.implicitly_wait(5)
    elem.send_keys(Keys.RETURN)
    driver.implicitly_wait(4)

The codes above are to get data from the website by entering a brand key to search bar. For some reason, elem.send_keys(brand) part causes an error saying element not intractable. I have no idea how to fix this! Any tips would be appreciated!

1 Answers1

1

Try below code

for brand in brands2:

driver.get('http://car.bitauto.com/')
elem = driver.find_element_by_id('cx-searchBox')
elem.click()
elem.send_keys(brand)
# The error occurs at this part
element = WebDriverWait(driver, 5).until(
    EC.element_to_be_clickable((By.XPATH, "// input[ @ id = 'yccmp-searchBtn']")))
element.click()

Note : Add below imports to your solution

from selenium.webdriver.support.ui import WebDriverWait
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
SeleniumUser
  • 4,065
  • 2
  • 7
  • 30