Auto-populate inputs with js / jquery

Asked

Viewed 93 times

-3

I was doing some tests with automation Javascript/jQuery and I came across some websites that it is not possible to fill in the entries correctly.

This would normally work on most websites:

$("#usuário").val('MY_USER')
$("#pass").val('MY_PASSWORD')
$("#send").click()

But on some specific websites, it doesn’t work. Is there any way to create code that works on any input?

It seems to me that one of the websites I’m testing checks the event of keydown to insert the value to the input.

  • This question is outside the scope of the Stack Overflow in Portuguese, write only questions in Brazilian Portuguese here, or use the Stack Overflow to publish this question.

  • Sorry! I edited for English!

  • There is an accent on the name of one of the inputs $("#usuário").val('MY_USER') this may be a cause. I have seen sites have incorrect elements with the same ID, if one of the websites you are testing has this condition this may also be a problem. Use console.log($("#usuário")) to know if the element returned by this query actually corresponds to the input desired, and if possible share one of the websites that your code does not work as well as the code used to have a test case.

1 answer

1

You can use the function attr(), defining an attribute:

$("#usuário").attr('value', 'MY_USER'); // Irá definir o atributo "value" para 'MY_USER'
$("#pass").attr('value', 'MY_PASSWORD'); // Irá definir o atributo "value" para 'MY_PASSWORD'

OBS: The function attr can define any attribute you want.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.