python selenium - Element is not currently interactable and may not be manipulated

匿名 (未验证) 提交于 2019-12-03 00:46:02

问题:

I am trying to populate form fields via selenium in python:

from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains  driver = webdriver.Firefox()         driver.get("http://www.miralinks.ru/") driver.implicitly_wait(30) login = driver.find_element_by_css_selector('input[placeholder="Логин"]') hov = ActionChains(driver).move_to_element(login) hov.perform() login.clear() login.send_keys("login") pwd = driver.find_element_by_css_selector('input[placeholder="Пароль"]') pwd.clear() pwd.send_keys("pass") 

but this fails with exception:

Element is not currently interactable and may not be manipulated

Why this happens and gow to fix this?

webdriver __version__ = '2.45.0'.

回答1:

The problem is that there are two other input elements with placeholder="Логин" and placeholder="Пароль" which are invisible. Make your CSS selectors specific to the login form:

login = driver.find_element_by_css_selector('form#loginForm input[placeholder="Логин"]') pwd = driver.find_element_by_css_selector('form#loginForm input[placeholder="Пароль"') 


回答2:

For me, the problem was because another element was overlaying the input box. In my case, there was a fancy label in place of a placeholder that animates upwards on click.

The trick was to click on the label first to trigger the animation and then fill in the input field



回答3:

I had this problem as well, but in my case the cause was slightly different. I needed to specify the size of the window before navigating to the page:

driver.Manage().Window.Size = new Size(width, height); 

This is because the default window size was rendering the page at a width where a media query had hidden the element, which caused the "Element is not currently interactable and may not be manipulated" error.



回答4:

Here xpath selectors working.

login = driver.find_element_by_xpath('//*[@id=\'loginForm\']/div/div[1]/input') pwd = driver.find_element_by_xpath('//*[@id=\'loginForm\']/div/div[2]/input') 

or same but css selector

login = driver.find_element_by_css_selector('form#loginForm [name="data[User][login]"]') pwd = driver.find_element_by_css_selector('form#loginForm [name="data[User][password]"]') 


回答5:

Sometimes it takes time to load the page. You can add wait statement. Try using "Thread.sleep(3000)"



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