i use selenium to complete the form in a part of the form, I have two text boxes that I complete with the codes below
username='something' #In the initial state, they do not have a value
password=something #In the initial state, they do not have a value
input_username=driver.find_element(By.XPATH,value="//input[@id='username_txt']")
input_username.click()
input_username.send_keys(username)
input_password=driver.find_element(By.XPATH,value="//input[@id='password_txt']")
input_password.click()
input_password.send_keys(password)
How can I make Selenium wait for the values of username and pass (to be generated through another function) I don't know how to generate username and pass How long does it take
In other words, I want to tell Selenium, whenever the value for two variables comes, enter them into the text boxes and wait until then and don't close the browser.
CodePudding user response:
You just need to put the method(s) generating the username and the password before sending the text into the input elements. Something like the following:
username = generate_username()
password = generate_password()
# generate_username() and generate_password() are methods you need to implement
input_username=driver.find_element(By.XPATH,value="//input[@id='username_txt']")
input_username.click()
input_username.send_keys(username)
input_password=driver.find_element(By.XPATH,value="//input[@id='password_txt']")
input_password.click()
input_password.send_keys(password)
We can also help with implementing the generate_username()
and generate_password()
methods if you can provide the requirements for their outputs.