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

前端 未结 6 1962
庸人自扰
庸人自扰 2021-01-17 11:59

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

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

         


        
相关标签:
6条回答
  • 2021-01-17 12:28

    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]"]')
    
    0 讨论(0)
  • 2021-01-17 12:33

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

    0 讨论(0)
  • 2021-01-17 12:41

    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

    0 讨论(0)
  • 2021-01-17 12:45

    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.

    0 讨论(0)
  • 2021-01-17 12:50

    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="Пароль"')
    
    0 讨论(0)
  • 2021-01-17 12:53

    Use a wait function before the element that gave the error.

    The webdriver is trying to interact with an element not completely loaded.

    0 讨论(0)
提交回复
热议问题