1

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.

3
  • I dont know if I understood correctly: Basically you want to write java application which uses Selenium to take certain action. That application asks me only for login name and password and uses it to log in for me. Am I right? Commented Jan 3, 2013 at 10:41
  • Then I also do not see any value added. User is required to do exactly same amount of work as if the process is not automated. Please edit your question and add some real user story why you need it... Commented Jan 3, 2013 at 12:26
  • It would take a few hundred lines of code using Netty library to be able to use a echo server to echo prompt you in the same way a chat server works. It's difficult and can be done but not worth the effort if you ask anyone. Commented Feb 24, 2013 at 22:17

3 Answers 3

3

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I used scanner for taking input from user, it's ask user to enter input in console. But I want to prompt in browser when we open url using following code : driver.get(url);
I think you are going to have to give us some more information about why you are doing this. At the moment I don't understand why you would want to do that.
0

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.

Comments

0

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.

Comments

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.