1

I'm using Selenium with Python, and I'm trying to complete a login form, I've succeed to complete the username field, but could not complete the password. This is the html:

<div class="loginNotVodafone" style="">

        <form id="loginNotVodafone" name="loginNotVodafone" action="https://urlblabla" method="post">      
          <!-- // GDPR select -->

          <fieldset>
          <input type="text" id="userFake2" name="userFake2" value="" autocomplete="off" placeholder="Username">
          <input type="hidden" id="user" name="UserName" class="hiddenTwo" value="">
          </fieldset>

          <fieldset>
          <input id="password" name="Password" value="" type="password" autocomplete="off" placeholder="Password">
          </fieldset>

        </form>
</div>

and this is my code:

inputuser = driver.find_element_by_id("userFake2")
inputuser.send_keys('[email protected]')
sleep(1);

password = driver.find_element_by_xpath(".//fieldset[.//input[@id='password']]")
password.click()
sleep(1);
password.send_keys('password')

I always receive the error:

selenium.common.exceptions.ElementNotVisibleException: Message: element not 
visible

Traceback:

Traceback (most recent call last):
File "C:\Users\stefa\eclipse-workspace\main.py", line 36, in <module>
password.send_keys('password')
File "C:\Users\stefa\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 479, in send_keys
'value': keys_to_typing(value)})
File "C:\Users\stefa\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 628, in _execute
return self._parent.execute(command, params)
File "C:\Users\stefa\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "C:\Users\stefa\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible
(Session info: chrome=67.0.3396.99)
(Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.17134 x86_64)

EDIT: with this commands i can let the cursor blink in the password field:

password = driver.find_element_by_xpath("//*@id='loginNotVodafone']/fieldset[2]").click()
password.send_keys('password')

but got the error message:

password.send_keys('password')
AttributeError: 'NoneType' object has no attribute 'send_keys'
2
  • Can you post the full TraceBack Commented Aug 2, 2018 at 13:05
  • added in the post Commented Aug 2, 2018 at 13:25

2 Answers 2

1

there was a problem in the xpath, so i've used an addon called ChroPath for Chrome and it gave me the correct absolute and relative path

so the correct command was:

password = driver.find_element_by_xpath("/html[1]/body[1]/div[3]/div[1]/div[1]/div[1]/div[4]/form[1]/fieldset[3]/input[1]").send_keys('password')

or relative Xpath:

password = driver.find_element_by_xpath("//form[@id='loginNotVodafone']//input[@id='password']").send_keys('password')
Sign up to request clarification or add additional context in comments.

Comments

0

Try to use WebDriverWait:

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "Password")))

Note: you have to add some imports:

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By

WebDriverWait will wait at least 10 seconds until element will be clickable and only then clicks on it. The whole code will be like this:

inputuser = driver.find_element_by_id("userFake2")
inputuser.send_keys('[email protected]')

password = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "Password")))
password.click()
sleep(1); # make sure, that you really need this pause
password.send_keys('password')

EDIT: you can try also to use JavaScript:

inputuser = driver.find_element_by_id("userFake2")
inputuser.send_keys('[email protected]')

password = driver.find_element_by_id("password")
driver.execute_script("arguments[0].click();", password)
sleep(1); # make sure, that you really need this pause
password.send_keys('password')

9 Comments

thanks for your help, but now i'm getting the "TimeoutException(message, screen, stacktrace)", it still not find the password field
Is this field visible on the browser? Are you sure that this filed is in HTML you have posted?
I have added information to my answer, please have a look
i've updated the page's code with some other information (sorry i'm not and expert in this field). The full Traceback is in the main post
have you tried driver.execute_script("arguments[0].click();", password) ?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.