简体   繁体   中英

insert text into webform using javascript

so i have this bot that i want to create that will simulate user input. the website i am using is WattsApp web. when i type a message into the website it enables a button that allows the message to be sent.

when i run my script it finds the input box (where i would type in manual). it then changes the innerHTML to a test string. it then finds the send button and clicks it.

the problem is that when i change the innerHTML the send button is not enabled. i have been searching for a long time to see why and i can not see a difference between manually typing in text and using a script for it. here is my script:

document.getElementsByClassName("input")[1].innerHTML="TestString!!!";
var input = document.getElementsByClassName("icon btn-icon icon-send send-container");
input[0].click();

but it get a error when i run the second line because the class "icon btn-icon icon-send send-container" can not be found except if i manual type in text. can anyone help? is there a difference between chaining the inner HTML and typing in text?

icon, btn-icon, icon-send , and send-container are all specific class names of the element you are selecting. Use one of them instead like below.

document.getElementsByClassName("icon");

or

var input = document.getElementsByClassName("btn-icon");

or

 var input = document.getElementsByClassName("icon-send");

continues ...based on your need

你的类名是错误的,只使用发送容器

When trying to set the value of inputs, you need to set the value

Given: <input id="myTextBox" />

SetValue: document.getElementById('myTextBox').value = 'MyInput';

Reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM