0

I want to send multiple input values for the same input field in selenium using python. Below is my code for sending only a single value to the input field. I want to test and run for multiple values.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver=webdriver.Firefox(executable_path='path')   
driver.get("http://site")    
username = driver.find_element_by_id("username")  
password = driver.find_element_by_id("password")   
username.send_keys("username")  
password.send_keys("password")  
#call the submit button
driver.find_element_by_CSS_selector('#form-login .button')click()
4
  • 1
    why do you want to do that? Commented Feb 4, 2019 at 7:20
  • you mean to say performing login check based on different username and password combinations ? Commented Feb 4, 2019 at 7:25
  • if you are agree with @NarendraR then you should use clear() for clear the field and you can send it back different value by sendKeys() Commented Feb 4, 2019 at 7:29
  • @narendraR yes ,i want to try for multiple username and password combination.I'm New to selenium,can anyone tell me how can i do this Commented Feb 5, 2019 at 9:49

1 Answer 1

3

You can use dictionary to achieve this. First declare a dictionary with the user name / password combination you want. Then using foreach you can iterate through this & check for multiple combination

userpass = {
    "user1":"pass1",
    "user2":"pass2",
    "user3":"pass3"
}

for un in userpass:
    username.send_keys(un)  
    password.send_keys(userpass[un])
    #rest of your actions
Sign up to request clarification or add additional context in comments.

1 Comment

Nice approach for having dictionary.

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.