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

3,958 views
Skip to first unread message

shammi

unread,
Jan 3, 2013, 5:32:19 AM1/3/13
to seleniu...@googlegroups.com
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.

MMOpta

unread,
Jan 3, 2013, 6:21:21 AM1/3/13
to seleniu...@googlegroups.com
Please be more specific? So, you want Selelenium to visit a Website and wait until the user has entered data? Then use the data to register him at facebook for example?

Here is what i would do:

1. Write simple html page with a username field, password field and a button (not a submit button) add some javascript to the button (set var "userHasEnteredData" to true).
2. Try this pseudo code:
while (userHasEnteredData == false){
Thread.sleep(1000ms);
}
3. Selenium read input fields, register at all porn sites ... etc

I hope this helps

shammi

unread,
Jan 3, 2013, 6:36:11 AM1/3/13
to seleniu...@googlegroups.com
See I have case, where I need user Input, so I want to prompt for user in browser to enter their input. As like scanner do in java but it's ask in console to enter input. I want to prompt in browser. 

MMOpta

unread,
Jan 3, 2013, 6:45:04 AM1/3/13
to seleniu...@googlegroups.com
so, what is wrong about my solution?
selenium.open("http://urlwiththedescribedpage/");

Shaba K

unread,
Jan 3, 2013, 6:56:13 AM1/3/13
to seleniu...@googlegroups.com
When you say a prompt is it a dialog box  ???




--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/yMtcQMqfqXMJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

shammi

unread,
Jan 3, 2013, 7:09:51 AM1/3/13
to seleniu...@googlegroups.com
Hi MMOpta, 
                  Actually, I don't want to wait for user to enter their input. I want to prompt dialog box for them to enter their Input.

shammi

unread,
Jan 3, 2013, 7:10:49 AM1/3/13
to seleniu...@googlegroups.com
Hi Shaba, 
                   Yes ...

MMOpta

unread,
Jan 3, 2013, 7:15:44 AM1/3/13
to seleniu...@googlegroups.com
Even if you use a dialog box, you will have to wait until they press ok ;) so the logic will be the same

shammi

unread,
Jan 3, 2013, 7:21:32 AM1/3/13
to seleniu...@googlegroups.com
Hi MMOpta, 
                   I understand, but just want to know Is there is way so we can prompt dialog box for user input?

MMOpta

unread,
Jan 3, 2013, 10:31:06 AM1/3/13
to seleniu...@googlegroups.com
// Some Java code

@Test
public void bla() throws InterruptedException{
   
String eval = "";
   
boolean hasEnteredText = false;
   
do{
      askForEmail
(selenium);
     
try{
         
while (!(eval = driver.switchTo().alert().getText()).equals("")) {
               
Thread.sleep(100L);
               
}
         
} catch (NoAlertPresentException e) {
     
}
           
   
if((eval = selenium.getEval("mememe")) != null && ( eval != "" ) && (!eval.equals("undefined")) ) {
       hasEnteredText
= true;
   
}
   
}while(!hasEnteredText);
   
System.out.println(eval);  
}

public void askForPassword(final Selenium selenium){
    askForText
(selenium,"password");
}

public void askForEmail(final Selenium selenium){
    askForText
(selenium, "mememe");
}

public void askForText(final Selenium selenium, final String text){
        selenium
.runScript(text
               
+ " = prompt(\"please enter your " + text + "\", \""+text+"\");");
}

Something like this should do the job i think you will fiddle it out good luck.


Am Donnerstag, 3. Januar 2013 11:32:19 UTC+1 schrieb shammi:
Reply all
Reply to author
Forward
0 new messages