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

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

4 Answers4

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')
cruisepandey
  • 28,520
  • 6
  • 20
  • 38
  • It is also not working I am attaching the website trying to scrape http://backgriduk.medialava.com/pages/Staff/Backlog.aspx?AUTH_TOKEN=QVVUSF9LRVlfT1JHQU5JWkFUSU9OX0lEPTd8LXxBVVRIX0tFWV9VU0VSX0lEPTUyOTF8LXxBVVRIX0tFWV9JUD0xMTQuMTQzLjMxLjIwMnwtfEFVVEhfS0VZX0NPT0tJRV9OQU1FPUZBTl82MzY1NjgwMjQyMjUyMTAwMDB8LXxBVVRIX0tFWV9DT09LSUVfTlVNQkVSPTUyMjJ8LXxBVVRIX0tFWV9ET01BSU49L3wtfEFVVEhfS0VZX1RJTUU9My8xNi8yMDE4IDE6MDc6MDIgUE18LXw1&LANGUAGE_ID=3 – abhishek gupta May 30 '19 at 09:04
  • EDIT 2 you can use too for more stability. – cruisepandey May 30 '19 at 09:31
  • It should work fine , though I'm not clicking on login button. – cruisepandey May 30 '19 at 09:55
  • Thanks but sometimes it works and sometimes it doesn't. I don't know whay it is behaving like that – abhishek gupta May 30 '19 at 10:07
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()
bharatk
  • 4,202
  • 5
  • 16
  • 30
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

KunduK
  • 32,888
  • 5
  • 17
  • 41
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

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352