3

I am trying to login to Gmail with two users. The data is exported from excel.

Sometimes my test passes, but sometimes the first user login and logout processes successfully, but the second username is not entered completely - the test jumps to the password field and enters the remaining part of the username in the password field with the password.

How do I stop this happening? Will forcing SendKeys to enter data more slowly help?

  • Could you give some more information, please? Do you have the same problem using sendkeys with hard-coded data? What errors are you getting? You haven't given enough information for good answers. – Kate Paulk Dec 3 '14 at 11:49
  • Actually I am trying to login gmail for two user and exporting data from excel. Some times test passes but some time first user login and logout successfully but second username are not typing complete username and they jump into password file, reaming part of username also typed in password field with password. Actually I want sendkey ,,send data to filed little slowly. – KKROYIT Dec 4 '14 at 12:53
  • I've put this information into the body of your question and edited the question so it's clearer what you're trying to do. I'm not a Selenium or TestNG expert myself, but that might help someone who is to give you the information you need. – Kate Paulk Dec 5 '14 at 12:21
  • If you watch the page with developer tools open, is it sending AJAX requests while you type? I've seen some things fail due to validation being slower than you typed. – Yamikuronue May 7 '15 at 21:15
3
  1. First, wait for the page to load completely (Code from this question).

    void waitForLoad(WebDriver driver) 
    {
    ExpectedCondition pageLoads = new
        ExpectedCondition() {
            public Boolean apply(WebDriver driver) {
                return (Boolean)((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete");
            }
        };
    WebDriverWait wait = new WebDriverWait(driver, 30);
    wait.until(pageLoads);
    }
    
  2. Clear Username field and then type username

    username.clear();
    //verify username is equal to ""
    if(username=="")
    username.sendKeys("your username");
    //verify username is typed correctly
    
  3. Clear password field and then type password

    password.clear();
    //verify username is equal to ""
    if(password=="")
    password.sendKeys("your password");
    //verify password
    

The above + using some explicit waits is just to make the script a little more stable.

0

I think there is problem of latency. So I will suggest you to try slowing your test scripts after first test run. Give enough time to the browser to logout completely and then read inputs for second test and then you pass them into the test scripts. The only thing here is you have to pass values only then when browser have successfully loaded the login page again.

Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.