2

I am trying to send keys via selenium it is taking for username but not for password.

I have tried clicking and sending keys then.

HTML of password field:

<div>
    <input name="txtPassword" type="password" id="txtPassword" required="" style="margin-bottom:0px;" class="blur">
    <a id="btnSmallForgotPassword" class="smallForgotPassword visible-sm-block" href="javascript:__doPostBack('btnSmallForgotPassword','')">forgot password</a>
</div>
WebDriverWait(driver, 3).until(EC.visibility_of_element_located((By.ID,"txtPassword"))).click()
WebDriverWait(driver, 3).until(EC.visibility_of_element_located((By.ID,"txtPassword"))).send_keys("san")

I am getting no error message but it is not sending keys for password

1
  • it worked once or twice but fails after sometime Commented May 30, 2019 at 9:54

4 Answers 4

1

try with this code :

WebDriverWait(driver, 3).until(EC.element_to_be_clickable((By.ID,"txtPassword"))).send_keys('your_password')

You should not create object of WebDriverWait too many times, use it like this :

wait = WebDriverWait(driver,10)

wait.until(EC.element_to_be_clickable((By.ID,"txtPassword"))).click()
wait.until(EC.element_to_be_clickable((By.ID,"txtPassword"))).send_keys('your_password')

and wait.until(EC.element_to_be_clickable((By.ID,"txtPassword"))) returns a web element, where you can use methods like click(), clear(), send_keys() etc.

You can write your code like this also :

password_field = wait.until(EC.element_to_be_clickable((By.ID,"txtPassword")))
password_field.click()
password_field.send_keys('your_password')

EDIT1 :

You can use this css selector :

input[id='txtPassword']

EDIT 2 :

You can use this full method :

wait = WebDriverWait(driver,10)

driver.maximize_window()
driver.get("http://backgriduk.medialava.com/pages/Staff/Login.aspx?LANGUAGE_ID=3&O=7")

wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"input[id='txtUser']"))).send_keys("abhishek")

wait.until(EC.element_to_be_clickable((By.ID,"txtPassword"))).click()
wait.until(EC.element_to_be_clickable((By.ID,"txtPassword"))).send_keys('your_password')
Sign up to request clarification or add additional context in comments.

4 Comments

It is also not working I am attaching the website trying to scrape backgriduk.medialava.com/pages/Staff/…
EDIT 2 you can use too for more stability.
It should work fine , though I'm not clicking on login button.
Thanks but sometimes it works and sometimes it doesn't. I don't know whay it is behaving like that
1

Try this:

from selenium import webdriver
import time

driver = webdriver.Chrome('/usr/bin/chromedriver')
driver.get('http://backgriduk.medialava.com/pages/Staff/Login.aspx?LANGUAGE_ID=3&O=7')
time.sleep(3)

username = driver.find_element_by_id("txtUser")
username.clear()
# insert username
username.send_keys("mrcats")

password = driver.find_element_by_name("txtPassword")
password.clear()
# insert password
password.send_keys("catskillz")

login = driver.find_element_by_name("btnLogin")
#click on login button
login.click()

Comments

0

The above code should work.However I have tested following code on chrome browser and working fine.

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

driver = webdriver.Chrome()
driver.get('http://backgriduk.medialava.com/pages/Staff/Login.aspx?LANGUAGE_ID=3&O=7')
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.ID,'txtUser'))).send_keys("Abhishek")
WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.CSS_SELECTOR,'div.divInnerRightControls #txtPassword'))).send_keys("Abhishek")

Output: Login form

Comments

0

To send character sequence to the USER ID and PASSWORD field you need to to induce WebDriverWait for the element to be clickable and you can use the following Locator Strategy:

  • Code Block:

    from selenium import webdriver
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.common.by import By
    
    driver = webdriver.Firefox(executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
    driver.get("http://backgriduk.medialava.com/pages/Staff/Login.aspx?LANGUAGE_ID=3&O=7")
    WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"input#txtUser"))).send_keys("abhishek_gupta")
    driver.find_element_by_css_selector("input#txtPassword").send_keys("abhishek_gupta")
    
  • Browser Snapshot:

userid_password

4 Comments

Hi Debanjan your solution sometimes work and sometimes it does'nt.
@abhishekgupta A bit unclear to me what you exactly mean by ...sometimes work and sometimes it doesn't... :) If it works once, it will always work unless the system RAM and memory requirements falls short. Btw, do you see any error?
I do not see any error it simply doesn't send keys to password.
@abhishekgupta Are you sure you are triggering the tests on a clean slate without any dangling webdriver instances?

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.