0

I'm trying to get to the results page of a search but I have to first click on the dropdown option to complete the search. When I do this manually, the dropdown hides if I do not click on it right as it appears, when I code it, I get a the following error:

ElementNotInteractableException: Message: Element <div id="_esgratingsprofile_autocomplete-results-container" class="autocomplete-results-container msci-ac-search-data-dropdown"> could not be scrolled into view

This is my code so far, you can visit the url and see how it is yourself as well:

from selenium.webdriver import Firefox
from selenium.webdriver.support.ui import Select
from selenium.webdriver.firefox.options import Options
opts = Options()
opts.set_headless()
assert opts.headless
browser = Firefox(options=opts)
browser.get('https://www.msci.com/esg-ratings')
search_form = browser.find_element_by_id('_esgratingsprofile_keywords')
search_form.send_keys('MSFT')
browser.find_element_by_xpath("//div[@id='_esgratingsprofile_autocomplete-results-container']/ul[@id='ui-id-1']/li[@class='msci-ac-search-section-title ui-menu-item']").click()

I looked through many other answers but they didnt seem to deal with the case where the dropdown was not a directly clickable element or where it hides if you dont click on it right away. Any help is appreciated.

Migos
  • 148
  • 9

1 Answers1

2

Try the below code, This code is working for me. Let me know if it shows any error.

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.maximize_window()
wait = WebDriverWait(driver, 5)
action = ActionChains(driver)

driver.get("https://www.msci.com/esg-ratings")

Drop_Down = driver.find_element_by_xpath('//*[@id="_esgratingsprofile_keywords"]')
Drop_Down.send_keys("MSFT")

# Select the First Result from the search.
Result = wait.until(
    EC.presence_of_element_located((By.XPATH, "//div[contains(@class,'autocomplete-results-container')]/ul/li[1]")))
action.move_to_element(Result).click().perform()
Swaroop Humane
  • 1,770
  • 1
  • 7
  • 17
  • Thanks! This is working for me and will accept the answer. Just a question, is there a way using chrome to run this without actually opening up a browser? – Migos Aug 12 '20 at 05:30
  • `from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_options.add_argument("--headless") driver = webdriver.Chrome(options=chrome_options)` – Swaroop Humane Aug 12 '20 at 05:32
  • Take help from this thread - https://stackoverflow.com/questions/53657215/running-selenium-with-headless-chrome-webdriver – Swaroop Humane Aug 12 '20 at 05:33