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,320 points
2,352 views

1 answer to this question.

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,910 points

Related Questions In Selenium

+10 votes
17 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,360 points
198,321 views
0 votes
1 answer

Not able to upload a file in Selenium Webdriver using python Scripting

Hey Srinivas, you can checkout this code ...READ MORE

answered Sep 10, 2019 in Selenium by Abha
• 28,140 points
4,213 views
0 votes
2 answers

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,500 points
13,776 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,190 views
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,910 points
7,267 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,904 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,910 points
7,807 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,910 points
2,786 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP