N
N
nakureniyvolshebnik2020-06-20 19:28:47
Python
nakureniyvolshebnik, 2020-06-20 19:28:47

How to fix Selenium. Message: Element could not be scrolled into view?

Throws an error during list selection. Help me please.
The code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
driver = webdriver.Firefox()
driver.get("https://kwork.ru/login")
element = driver.find_element_by_id("l_username")
element.send_keys("[email protected]")
element = driver.find_element_by_id("l_password")
element.send_keys("9Thb57G6x")
element = driver.find_element_by_css_selector("#form-login-page > div.w470.dib.v-align-m.foxForm__inner > div.row.form-entry > input.hugeGreenBtn.GreenBtnStyle.h50.pull-left.w240.m-wMax.mr10")
element.send_keys(Keys.ENTER)
cookies = driver.get_cookies()
for cookie in cookies:
    driver.add_cookie(cookie)
driver.get("https://kwork.ru/new")
select = Select(driver.find_element_by_xpath('//*[@id="body"]/div[6]/div[9]/form/div[5]/div[1]/div[2]/div[2]/div[1]/div[2]/div[1]/div[1]/select'))
select.select_by_value("83")
element = driver.find_element_by_id("editor-title")
element.send_keys("Напишу статью")

Error log:
Traceback (most recent call last):
File "main.py", line 17, in
select.select_by_value("83")
File "C:\Users\Dima\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8 _qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\support\select.py", line 82, in select_by_value
self._setSelected(opt)
File "C:\Users\Dima\AppData\Local\Packages \PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\support\select.py", line 212, in _setSelected
option.click()
File "C:\Users\Dima\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Users\Dima\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\remote\webelement. py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\Users\Dima\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site -packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Dima\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: Element could not be scrolled into view

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
ScriptKiddo, 2020-06-29
@ScriptKiddo

Most likely you need to wait until the drop-down list opens.
https://stackoverflow.com/a/51252175

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question