Not able to login using selenium webdriver using Java Language

0 votes

I’m not able to login using selenium webdriver using Java Language. It was working fine earlier.

Below is my HTML code:

<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>

Below is my code before the incident:

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

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

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");

Below is my full 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>

Jul 17, 2018 in Selenium by Martin
• 4,210 points
191 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Try to send text to the username and password field using below example:

driver.findElement(By.xpath("//input[@id='loginUsername']")).sendKeys("username");

driver.findElement(By.xpath("//input[@id='loginPassword']")).sendKeys("password");

answered Jul 17, 2018 by Samarpit
• 5,130 points

Related Questions In Selenium

+9 votes
13 answers

How to automate gmail login process using selenium webdriver in java?

Check the below code: Here is the working ...READ MORE

answered Apr 24, 2018 in Selenium by Vardy
• 2,280 points
34,605 views
0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,030 points
1,195 views
0 votes
1 answer

How to scroll the Page up or down in Selenium WebDriver? (using java)

Its pretty simple. Check out the below ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,030 points
4,279 views
0 votes
1 answer

How to handle Pop-up in Selenium WebDriver using Java

Actually, its pretty simple. Use this code ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,030 points
2,112 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,030 points
51 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
408 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
40 views
0 votes
1 answer

Firefox browser not opening with given URL using Selenium Webdriver with Java

Download the latest selenium jar and replace ...READ MORE

answered Apr 30, 2018 in Selenium by Samarpit
• 5,130 points
1,495 views
0 votes
1 answer

How to login a forum using Selenium with Python

You should try to directly log in ...READ MORE

answered Apr 27, 2018 in Selenium by Samarpit
• 5,130 points
148 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.