Selenium: Element is not currently visible and so may not be interacted
<p>I'm attempting to create an automated login script to netflix website: <a href="https://www.netflix.com/it/" rel="nofollow">https://www.netflix.com/it/</a></p>

<p>That's the code:</p>

<pre><code>from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox()
while True:
    driver.get("https://www.netflix.com/it/")
    login = driver.find_element_by_css_selector(".authLinks.signupBasicHeader")
    login.click()
    element = driver.find_element_by_name("email")
    element.send_keys("test1@email.com")
    submit = driver.find_element_by_css_selector(".btn.login-button.btn-submit.btn-small")
    submit.click()
    element2 = driver.find_element_by_name("password")
    element2.send_keys("test1")
    submit.click()
</code></pre>

<p>But sometimes it works and sometimes it doesn't and it raises this exception:</p>

<pre><code>Traceback (most recent call last):
  File "netflix.py", line 35, in &lt;module&gt;
    submit.click()
  File "/home/user/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webelement.py", line 72, in click
    self._execute(Command.CLICK_ELEMENT)
  File "/home/user/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webelement.py", line 461, in _execute
    return self._parent.execute(command, params)
  File "/home/user/.local/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
    self.error_handler.check_response(response)
  File "/home/user/.local/lib/python3.5/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
Stacktrace:
    at fxdriver.preconditions.visible (file:///tmp/tmp7otgskq8/extensions/fxdriver@googlecode.com/components/command-processor.js:10092)
    at DelayedCommand.prototype.checkPreconditions_ (file:///tmp/tmp7otgskq8/extensions/fxdriver@googlecode.com/components/command-processor.js:12644)
    at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmp7otgskq8/extensions/fxdriver@googlecode.com/components/command-processor.js:12661)
    at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmp7otgskq8/extensions/fxdriver@googlecode.com/components/command-processor.js:12666)
    at DelayedCommand.prototype.execute/&lt; (file:///tmp/tmp7otgskq8/extensions/fxdriver@googlecode.com/components/command-processor.js:12608)
</code></pre>

<p>The exception says that a part of the web page is invisible (even if that part IS in the page actually)... It's a sort of bug.
How can I bypass this?</p>

<p>No need to put the test code inside <code>while</code> loop, since login form should be submitted once. I guess when it works successfully, next iteration gives error since there is no form.</p>

<p>You are also clicking the submit button before and after password entry. It is better to click after form is fully filled, if possible and not testing empty form. </p>

<pre><code>from selenium import webdriver

driver = webdriver.Firefox()
driver.get("https://www.netflix.com/it/")
login = driver.find_element_by_css_selector(".authLinks.signupBasicHeader")
login.click()
element = driver.find_element_by_name("email")
element.send_keys("test1@email.com")
submit = driver.find_element_by_css_selector(".btn.login-button.btn-submit.btn-small")
submit.click()
element2 = driver.find_element_by_name("password")
element2.send_keys("test1")
submit = driver.find_element_by_css_selector(".btn.login-button.btn-submit.btn-small")
submit.click()
</code></pre>

python python-3.x selenium