Kevin
Kevin

Reputation: 157

How to insert text into texbox selenium c#

    <div class="input-container">

                <div class="form-group">
                    <div class="labelContainer">
                        <<p>Current Password<span>*</span></p>
                    </div>
                    <label for="currentPassword" class="sr-only">Current Password</label>
                    <input type="password" id="currentPassword" name="currentPassword" class="form-control" placeholder="Current Password" required="">
                    <i class="fa fa-lock icon-style" aria-hidden="true"></i>
                </div>

                <div class="form-group">
                    <div class="labelContainer">
                        <<p>Enter New Password<span>*</span></p>
                    </div>
                    <label for="newPassword" class="sr-only">New Password</label>
                    <input type="password" id="newPassword" name="newPassword" class="form-control" placeholder="New Password" required="">
                    <i class="fa fa-lock icon-style" aria-hidden="true"></i>
                </div>

                <div class="form-group">
                    <div class="labelContainer">
                        <<p>Confirm New Password<span>*</span></p>
                    </div>
                    <label for="confirmPassword" class="sr-only">Confirm New Password</label>
                    <input type="password" id="confirmPassowrd" name="confirmPassowrd" class="form-control" placeholder="Confirm Password" required="">
                    <i class="fa fa-lock icon-style" aria-hidden="true"></i>
                </div>

Above is the html code, I would like to insert the current password into current password text field. I have tried two methods below and it is not workable it says element not visible.

(code 1 )driver.FindElement(By.Id("currentPassword")).SendKeys("testabc");
(code 2 )IJavaScriptExecutor jse = (IJavaScriptExecutor)driver;
jse.ExecuteScript("document.getElementById('currentPassword').value='testabc';");

Try to test for newPassword textfield instead of currentPassword textfield and it is working fine. only the currentPassword and confirmPassword textfield have error message element not visible.

Does anyone know what is the problem?

Upvotes: 3

Views: 222

Answers (1)

Ishita Shah
Ishita Shah

Reputation: 4035

You may try this,

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
wait.Until(ExpectedConditions.ElementIsVisible(By.Id("currentPassword"))).SendKeys("testabc");

Upvotes: 3

Related Questions