0

At the moment in Eclipse, I have the following code:

driver.findElement(By.name("LoginText1")).clear();
System.out.println("Username: ");
Scanner scan1 = new Scanner(System.in);
String input1 = scan1.nextLine();
System.out.println(input1);

and was just wondering, instead of it simply returning the user's input in to the console, is there a way to get it to insert it in to the text field. I want to insert it into a field which has the name LoginText1. This is for website testing with Selenium WebDriver.
I am new to Java and all help is greatly appreciated.

1
  • Did either of the answers solve your problem? If so, mark it as solved? Commented Mar 28, 2013 at 17:44

4 Answers 4

1

You would simply do something like this

LoginText1.setText(input1);

I suggest looking into JTextField documentation and you would have quickly found examples and solutions to your problem.

Here

I also suggest looking into variable naming conventions (LoginText1 should start with a lowercase).

Here

EDIT

After seeing your most recent edit, you are wanting to fill in a form from a website using selenium webdriver. A post at StackOverflow shows just that using the sendKeys() method.

Here is the link

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

1 Comment

I added that, and also added import java.awt.TextField; but I get the error Logintext1 cannot be resolved. Also, I would change the name of the field if I could, but I don't have that sort of access. I am just supposed to make automated testing using Selenium for as many browsers as possible.
1

After seeing the edits on your question, I'm afraid I can only link you to Selenium's online documentation:

http://docs.seleniumhq.org/docs/

12 Comments

did you declare the textfield?
If you mean what you just changed, then no. I have done exactlty what you wrote: LoginText1 = new JTextField(20); LoginText1.setText(input1); But I still get the same error, but now in both places.
@D.Shah You need to really read into the basics of Java before jumping into Gui. Grab a book and start from the beginning.
I appreciate that, but I don't appear to have the time, and I think this is one of the only things I am having a problem with now. Also, I tried what you said, I didn't get the error, but it still doesn't enter the text in to the field. Also, what would I need the JFrame for?
I added the JFrame and the rest, but when I run it, it simply gives me a Java Pop-up with the username I entered. It still doesn't enter the username in to the field.
|
0

in this scenario user is passing the password manually through console.

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
                String password;   
                System.out.println("Please Enter the user password :: ");
                password= br.readLine();  
                driver.findElement(By.id("pwd")).sendKeys("password");

Comments

0

Pass your variable index wherever it is required.

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Index of the sheet: ");
int index = br.read();

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.