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.
-
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?Pavel Janicek– Pavel Janicek2013-01-03 10:41:41 +00:00Commented 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...Pavel Janicek– Pavel Janicek2013-01-03 12:26:23 +00:00Commented 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.djangofan– djangofan2013-02-24 22:17:26 +00:00Commented Feb 24, 2013 at 22:17
3 Answers
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.
2 Comments
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
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.