0

This is really weird but I suddenly cannot login using selenium. I was able to login with my code just a week ago and then I can't anymore. Here's the html code from the website:

<div class="form-group">
 <label for="loginUsername" style="width: 100%; font-weight: normal" aria-label="Username">
 <input id="loginUsername" class="form-control" name="username" type="text" placeholder="Username" autocapitalize="off">
</label>
</div>

<div class="form-group">
 <label for="loginPassword" style="width: 100%; font-weight: normal" aria-label="Password">
 <input id="loginPassword" class="form-control" name="password" type="password" placeholder="Password" autocapitalize="off">
</label>
</div>

And here is my code before the incident:

driver.findElement(By.xpath("//*[@id=\"loginUsername\"]")).sendKeys("username");
driver.findElement(By.xpath("//*[@id=\"loginPassword\"]")).sendKeys("password");

It worked fine before. I even tried changing it up and it looked something like this:

WebElement username = driver.findElement(By.xpath("//*[@id=\"loginUsername\"]")); username.click(); username.clear(); ;username.sendKeys("username");
WebElement password = driver.findElement(By.xpath("//*[@id=\"loginPassword\"]")); password.click(); password.clear(); ;password.sendKeys("password");

I honestly don't know what is wrong with my code and I didn't get any error too. I also tried using "By.name()" or "By.id()" but it still didn't work so I'm really confused. Please help me, thank you!

edited Here's the full version of the code

<div class="col-sm-4 col-sm-offset-4">
<form action="/login" method="post">
  <div class="form-group title">
  <img src="/img/RA_LOGO_BLUE.png" alt="Risk Assessment System Logo">
  </div>
<div class="form-group">
  <label for="loginUsername" style="width: 100%; font-weight: normal" aria-label="Username">
  <input id="loginUsername" class="form-control" name="username" type="text" placeholder="Username" autocapitalize="off">
  </label>
</div>
<div class="form-group">
  <label for="loginPassword" style="width: 100%; font-weight: normal" aria-label="Password">
    <input id="loginPassword" class="form-control" name="password" type="password" placeholder="Password" autocapitalize="off">
  </label>
    </div>
    <input id="loginBtn" class="btn" type="submit" value="Login">
  </form>
  <br>
  <div class="text-left">
    <span class="fakeLink" data-toggle="modal" data-target="#forgotPasswordModal">Forgot Password?</span><br>
    <span class="fakeLink" data-toggle="modal" data-target="#forgotUsernameModal">Forgot Username?</span>
  </div>
</div>

7
  • At what point does the process get stuck? Commented Mar 23, 2018 at 19:05
  • After entering the website url Commented Mar 23, 2018 at 20:17
  • You need to be more specific for us to help you. What's the error you get? Does the form get filled? Commented Mar 23, 2018 at 21:04
  • The form did not get filled Commented Mar 23, 2018 at 22:19
  • From this bit of code, it is hard to tell what is going on. Please provide a minimal reproducible example. Commented Mar 24, 2018 at 0:00

1 Answer 1

1

To send text to the username and password field you can use the following code block :

driver.findElement(By.xpath("//input[@id='loginUsername']")).sendKeys("username");
driver.findElement(By.xpath("//input[@id='loginPassword']")).sendKeys("password");
Sign up to request clarification or add additional context in comments.

2 Comments

try to send us more of HTML, maybe there are more inputs with the same id?
@NodirNasirov You saw it right. Certainly OP made some manipulation while providing the HTML. Having said that my answer was based on OP's initial code trial when there was no HTML with in the question !!!

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.