I have wrote an javascript code to automate a process in a chatbot website . The program will fetch some random quote using a free api and will fill the textarea with that quote and will click send button in the chat application. Although the textarea is getting populated but the send button is can't be clicked both manually or programmatically unless a character is typed manually into the textarea.
Code:
const getNewQuote = async () =>
{
//get Input Element and Send Button
var inputField = document.getElementsByClassName("bot-textarea")[0];
var sendbtn = document.querySelectorAll('[aria-label="Send"]')[0];
//api for quotes
var url="https://type.fit/api/quotes";
// fetch the data from api
const response=await fetch(url);
//convert response to json and store it in quotes array
const allQuotes = await response.json();
// Generates a random number between 0 and the length of the quotes array
const indx = Math.floor(Math.random()*allQuotes.length);
//Store the quote present at the randomly generated index
const quote=allQuotes[indx].text;
inputField.value = quote;
sendbtn.click();
}