Message: Element <option> could not be scrolled into view while trying to click on an option within a dropdown menu through Selenium

僤鯓⒐⒋嵵緔 提交于 2019-11-26 23:19:56

This error message...

selenium.common.exceptions.ElementNotInteractableException: Message: Element <option> could not be scrolled into view.

...implies that the <option> item which your program was trying to interact with could not be scrolled into view.

The HTML of the desired element would have given us some idea behind the error. However it seems the desired element was not clickable / within the Viewport. To address the issue you have to induce WebDriverWait for the element to be clickable and you can use the following solution:

mySelectElement = browser.find_element_by_id('providerTypeDropDown')
dropDownMenu = Select(mySelectElement)
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//select[@id='providerTypeDropDown']//options[contains(.,'Professional')]")))
dropDownMenu.select_by_visible_text('Professional')

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
from selenium.webdriver.support.select import Select

Try to add a wait:

mySelectElement = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "providerTypeDropDown")))
mySelectElement.click()

it will wait at least 10 seconds until element will be clickable and then click.

Also I don't see in your code, that you click on the dropdown button, which opens dropdown menu. Locate this button, also add a wait and click on it before you select the option. Hope it helps.

Note: for this code you have to add some imports:

from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!