Shammi
Shammi

Reputation: 203

How can I prompt for Input in selenium webdriver using java and use the result?

I want to take user input and perform action based on their Input. Let suppose take an example of login page, where user need to enter login credentials. How we can take user Input as his email and password and then use that email Id and password to as his login credentials.

Upvotes: 1

Views: 3307

Answers (3)

Ajay
Ajay

Reputation: 187

You can input your user name and password even before the script start. See below code

driver.findElementByXpath("xpath of username input box").sendkeys("Myusername");
driver.findElementByXpath("xpath of password input box").sendkeys("Mypassword");

This way you will be able to input login credentials for the user.

Upvotes: 0

Adi
Adi

Reputation: 93

As far as i understand by your question, you want to get only Login credentials from user that is using your Test and you dont want to include that in your automation script just for login purpose.

I dont think this solves the purpose for what selenium is used for. But still, if you want to do that i have a suggestion. After you reach your Login page implement the code for implicit wait till you get the page that will come up just after user click on login after providing credentials. You can check this by verifying for presence of some text on the page in wait condition.

Else, if you just want to absctract the credentials and worried about hardcoding it in your script, then you can use some spredsheets, Text files or MS-Excel file to store your data and can use the same as a resource file by calling through defined methods.

Upvotes: 0

Ben Butler-Cole
Ben Butler-Cole

Reputation: 2051

Getting input from a user in independent of your use of Selenium. You need to use standard Java mechanisms for getting user input (this question shows a couple of options), store the answer in a variable and then pass it to the Selenium code which fills in the form.

Upvotes: 3

Related Questions