D
D
DR_Demons2015-01-05 08:25:32
JavaScript
DR_Demons, 2015-01-05 08:25:32

How to click on jquery button using Selenium Webdriver?

Good day! The problem is that you need to log in to the site, but it doesn’t work, the program works without errors, but apparently does not perform the action of clicking on the "Login" button on which the jquery script is located

the code
<input id="UserName" type="text" maxlength = "16"  placeholder="Логин" value="" autocomplete="off" />
      <input id="Password" type="password" maxlength="6" placeholder="Пароль"  autocomplete="off">
      
      <a class="forgot" href="#">Я забыл логин или пароль</a>
        <p class="forget-block" style="display:none; margin-top:10px;">
          Просто позвоните по бесплатному номеру 8-800-700-787-7
        </p>
    </div>
    <a id="logonButtonId" class="btn" href="#">Войти</a>

script for this site
//Вход
  $('#logonButtonId').click(function (e) {
    e.preventDefault();
    if (!$(this).hasClass('disabled')) {
      if ($('#UserName').val() == '') {
        $('#UserName').focus();
        $('#UserName').addClass('error');
        return false;
      } 
      else if ($('#Password').val() == '') {
        $('#Password').focus();
        $('#Password').addClass('error');
        return false;
      } else {
        $('#logonButtonId').addClass('disabled');
        $('#Password').prop('disabled', 'disabled');
        $('#UserName').prop('disabled', 'disabled');
        $('#PasswordFromHidden').val($('#Password').val());
        $('#UserNameFromHidden').val($('#UserName').val());
        if ($('#CaptchaBlockId').length > 0) {
          $('#logonBlockId').hide();
          $('#CaptchaBlockId').show();
        } else {
          $('#loginFormId').submit();
        }
      }
    }
  });



The question is how to interact with it?

I do it in java, I tried to contact
So

element.findElement(By.id("logonButtonId")).click();
element.findElement(By.className("btn")).click();
element.findElement(By.xpath("/html/body[1]/div[1]/div[2]/div[2]/div[1]/div[1]/a[1]"))
there is no result, the code works, but is not authorized.

Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2015-01-05
@Nc_Soft

Have you filled out your username/password before?
element.findElement(By.id("logonButtonId")).click();

C
Che_Bu_Rashka, 2017-04-08
@Che_Bu_Rashka

How was the issue resolved? Also interesting...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question