Unable to input into a textfield?

Hello! I was practicing automation on a website, and found out that I'm unable to input into a input field? I tried all of these:
input.setAttribute("value", "100");
input.setAttribute("value", "100");
input.value = 100;
input.value = 100;
input.value = 100;
input.dispatchEvent(
new Event("input", { bubbles: true, cancelable: true })
input.value = 100;
input.dispatchEvent(
new Event("input", { bubbles: true, cancelable: true })
Last one should be the modern way of doing it, but while it did input it, it did not save it. Anyone knows what is the problem?
39 Replies
Jochem
Jochemā€¢16mo ago
Not sure what you mean, and it's hard to help without code. Setting the value should work: https://codepen.io/jochemm/pen/qBQLPme That last one (with dispatchEvent) is only really necessary if you want to trigger any event listeners that are listening to the input event on the element
Dovah
Dovahā€¢16mo ago
Oh. Hm, I will try it again tomorrow since I'm not able at the moment And will try to provide both code and explain it better if it does not work!
Brightie
Brightieā€¢16mo ago
I have one question, is the input a variable refering to the DOC-element? in other words, is it like this: let input = document.getElementsByTagName("input")[0] this code means that input refers to the first input tag in your html correct me if im wrong but you cant add an attribute to a non-defined element
Brightie
Brightieā€¢16mo ago
Here is what I am trying to say
Jochem
Jochemā€¢16mo ago
my assumption was that it is set somehow, but yeah, without code it's impossible to tell šŸ™‚
Brightie
Brightieā€¢16mo ago
That is true, the information I gave is based on the lack of code provided I was thinking of what could be the issue, looking at the bits of code he gave I assume he gave us the things he tried, but nowhere did I see him define the DOC-element he is trying to manipulate
Jochem
Jochemā€¢16mo ago
as a side note, btw, it's probably easier nowadays to use document.querySelector or document.querySelectorAll over document.getElementById or document.getElementsByTagName
Brightie
Brightieā€¢16mo ago
Well yeah, there are many ways to call upon elements xd I just gave this one because even if you are a beginner when it comes to coding, this one should be one of the easiest to understand As you can see the ID in the HTML-element and you can read in the js-code what you aree doing "getElementById" I don't know his level of coding, so I provided one that even a beginner should be able to follow
Dovah
Dovahā€¢16mo ago
Yes of course. My bad for not providing it. I selected the element with
const input = document.querySelector(".input");
const input = document.querySelector(".input");
Input is not my actual variable name, i just used it as an example I can also select it as
const randomInput = document.querySelectorAll(".input")
const randomInput = document.querySelectorAll(".input")
and call it with input[0]
Jochem
Jochemā€¢16mo ago
is the class on the element input, or are you trying to select an input element with that?
Brightie
Brightieā€¢16mo ago
could you put your code in codepen or codesandbox? As it would be easier for us to help you if we can play around with your code and see it in full
Dovah
Dovahā€¢16mo ago
That up there is the code. xD wait
Brightie
Brightieā€¢16mo ago
Then where is the html code?
Dovah
Dovahā€¢16mo ago
Its not my website, I'm doing an automation. Can;t really provide it.
Brightie
Brightieā€¢16mo ago
Does your javascript-file even link to the file you are trying to do the automation on?
Jochem
Jochemā€¢16mo ago
you're using ghostmonkey or something?
Dovah
Dovahā€¢16mo ago
Tamper šŸ˜¦ Let me explain it in detail Once more
Jochem
Jochemā€¢16mo ago
then share the userscript in full and the site you're trying to do this on?
Dovah
Dovahā€¢16mo ago
When I use
const input = document.querySelector(".input");
input.value = 100;
const input = document.querySelector(".input");
input.value = 100;
It changes the value visually, but not on their end. When I submit the form, the default value is submitted. Input field also has little arrows next to it, and after I input my "input.value = 100;" and click on the arrow to increment it by 1, it changes to default value and increments it by 1, instead of mine. Only way my value is accepted is if I do any keyboard click afterwards, while that input field is focsued. So my script is literally
const input = document.querySelector(".input");
input.value = 100;
const input = document.querySelector(".input");
input.value = 100;
I tried simulating keyboard events, such as keypress, keydown, keyup bot non works. šŸ˜¦
let evt = new KeyboardEvent('keypress', {key: "a});

let evett = new KeyboardEvent('keydown', {key: "a});

let evettt = new KeyboardEvent('keyup', {key: "a});



input.dispatchEvent(evt)

input.dispatchEvent(evett)

input.dispatchEvent(evettt)
let evt = new KeyboardEvent('keypress', {key: "a});

let evett = new KeyboardEvent('keydown', {key: "a});

let evettt = new KeyboardEvent('keyup', {key: "a});



input.dispatchEvent(evt)

input.dispatchEvent(evett)

input.dispatchEvent(evettt)
As I wrote, my "script" is like 2 lines that I provided. xD
Jochem
Jochemā€¢16mo ago
they might be storing the value some other way, there is no way to tell without seeing the whole site are there data attributes on the input? what event handlers are bound to the input when you inspect it?
Dovah
Dovahā€¢16mo ago
<input class="input" type="text" tabindex="1" data-field-type="inputValue" value="10">
<input class="input" type="text" tabindex="1" data-field-type="inputValue" value="10">
Here
Jochem
Jochemā€¢16mo ago
check the rest of the source of the website for calls to fetch
Dovah
Dovahā€¢16mo ago
Sec It has an event as well I think
Jochem
Jochemā€¢16mo ago
also, what are you trying to automate?
Dovah
Dovahā€¢16mo ago
It's a form. I'm automatically adding info, and submiting it.
Jochem
Jochemā€¢16mo ago
that sounds pretty shady tbh
Dovah
Dovahā€¢16mo ago
xD Ofc, I'm not 100% honest, but I can't really provide everything. But it literally is a form with that script. It is not malicious as well! it is a gambling website, and I'm trying to ease my input with this script.
Jochem
Jochemā€¢16mo ago
yeah, I'm not comfortable helping with that
Dovah
Dovahā€¢16mo ago
Check my post history here, I'm doing this as practice. With non-existent benefit, I just wanted to automate the procces instead of clicking. That is it But as saying "gambling website" will give that reaction. Either way, I still want to use this discord as my own means of practice, sicne it helped my a lot, so I will delete this post if it markes me as a scammer or fishy person. But I only did asked because I did not understand why such a simple thing does not work, not to scam someone. Pure practice.
Jochem
Jochemā€¢16mo ago
don't worry about it, I'm just personally not comfortable messing with gambling sites
Dovah
Dovahā€¢16mo ago
Roger. My apologies for being a round-about about this whole thing!
Jochem
Jochemā€¢16mo ago
honestly, if you're doing this for practice, I'd suggest picking a different site simply because a gambling site is going to have stuff in place to prevent exactly this thing
Dovah
Dovahā€¢16mo ago
Yeah. I tought so. xD It must be some kind of antichear thing. But I do not see the benefit, I'm just prebetting, that is why I did not understand it? Maybe because of bots?
Jochem
Jochemā€¢16mo ago
they're doing something funky on submit if setting .value isn't working. You'd have to read the code that does the submitting (which you could find by searching for the submit event handler on the form, or the click handler on the button, or by looking for fetch or FormData in the code) probably bots yeah, or just a general anticheat measure they implemented site-wide even for bits where it isn't necessary
Dovah
Dovahā€¢16mo ago
But it accept the value when I trigger keyboard event, before submit. So yeah, it must be to ensure it is type by hand and not like this. I just did not know it was possible.
Jochem
Jochemā€¢16mo ago
could be they're listening to keypress instead of keydown
Dovah
Dovahā€¢16mo ago
It is a 2 step, input and submit, it does not change it for me, But it was driving me crazy I will admit. xD I tried both, maybe I wrote it wrong? Either way, yeah, it must be something much more complicated. It was pure curiosity that was driving me nuts, since I did manage to do it on 1 other betting website, but this one did not budge. xD I will not bother you anymore, my apologies. But I swear it was pure curiosity! Not to scam or anythinh, like implementinh my knowledge irl for the firstr time. xD anything* implementing*
Jochem
Jochemā€¢16mo ago
's all good, no worries
Dovah
Dovahā€¢16mo ago
Cheers! And thanks. Pretty sure you helped me more than few times before, I recognize your name! šŸ«”
Want results from more Discord servers?
Add your server