Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法从隐藏-Python-Selenium的下拉列表中选择元素_Python_Selenium_Web Scraping_Drop Down Menu - Fatal编程技术网

无法从隐藏-Python-Selenium的下拉列表中选择元素

无法从隐藏-Python-Selenium的下拉列表中选择元素,python,selenium,web-scraping,drop-down-menu,Python,Selenium,Web Scraping,Drop Down Menu,我试图进入搜索结果页面,但我必须先单击下拉选项以完成搜索。当我手动执行此操作时,如果我没有正确单击下拉列表,下拉列表将隐藏。当我对其进行编码时,我会收到以下错误: ElementNotInteractableException: Message: Element <div id="_esgratingsprofile_autocomplete-results-container" class="autocomplete-results-container ms

我试图进入搜索结果页面,但我必须先单击下拉选项以完成搜索。当我手动执行此操作时,如果我没有正确单击下拉列表,下拉列表将隐藏。当我对其进行编码时,我会收到以下错误:

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

我看了很多其他的答案,但它们似乎没有处理下拉列表不是可直接单击的元素或者如果你不立即单击它,它就会隐藏的情况。非常感谢您的帮助。

请尝试以下代码,此代码适用于我。如果有任何错误,请告诉我

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()

试试下面的代码,这个代码对我有用。如果有任何错误,请告诉我

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()

使用javascriptexecutor执行单击action@Shrini即使元素没有滚动到视图中,这是否也可以工作?请使用javascriptexecutor执行单击action@Shrini即使该元素未滚动到视图中,此操作是否有效?谢谢!这对我有效,我会接受答案。只是一个问题,有没有一种方法可以在不打开浏览器的情况下使用chrome来运行它?
从selenium导入webdriver从selenium.webdriver.chrome.options导入选项chrome\u options=options()chrome\u options.add\u参数(“--headless”)driver=webdriver.chrome(options=chrome\u options)
从此线程获取帮助-谢谢!这对我有效,我会接受答案。只是一个问题,有没有一种方法可以在不打开浏览器的情况下使用chrome来运行此操作?
从selenium导入webdriver从selenium.webdriver.chrome.options导入选项chrome\u options=options()chrome\u options.add\u参数(“--headless”)driver=webdriver.chrome(options=chrome\u options)
从此线程获取帮助-