3

I'm trying to search for a company, arrow down and click enter on inhersight.com

I have the following code but it doesn't seem to work:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver.get("https://www.inhersight.com/companies")
elem = driver.find_element_by_class_name("open-search.small-hide.margin-right-20.icon-36.icon-search.reverse.cursor-pointer").click()
elem.send_keys("Apple")
elem.send_keys(Keys.ARROW_DOWN)

It doesn't seem to be able to locate and find the element by the class name. I've tried many things but it still doesn't work... I'm lost

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

2 Answers2

0

To search for a company and click enter on inhersight.com instead of as the elements are Auto Suggestions so instead of arrow down you need to induce WebDriverWait for the desired element to be clickable and you can use the following solution:

  • Code Block:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.wait import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    options = Options()
    options.add_argument('start-maximized')
    options.add_argument('disable-infobars')
    options.add_argument('--disable-extensions')
    driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
    driver.get("https://www.inhersight.com/companies")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".open-search.small-hide.margin-right-20.icon-36.icon-search.reverse.cursor-pointer"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@placeholder='Search women-rated companies']"))).send_keys("Apple")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//li[contains(@class,'select2-highlighted')]/div[@class='select2-result-label']/div[@class='weight-medium']"))).click()
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

You could avoid the selections as the company name becomes part of the query string in the URL, with spaces replaced by "-" and all lower case. You can therefore direct .get on this formatted URL. You can add some handling in for if company not found.

from selenium import webdriver
company = 'Apple Federal Credit Union' # 'apple'
base = 'https://www.inhersight.com/company/' 
url = base + company.replace(' ', '-').lower()

d = webdriver.Chrome()
d.get(url)

#other stuff including handling of company not found (this text appears on the page so not hard)
#d.quit()
QHarr
  • 83,427
  • 12
  • 54
  • 101