How to get text from element and save it to a new line in .txt file using javascript?

So, as the title says, I want to get a text from an element on the web page inside my web browser and save it in a .txt file’s new line, but first copy it to clipboard.

It works, but it is always stuck at the same element (clipboard save doesn’t change when the text in element is changed so it keeps pasting the same text

here is the code:

CurBrowser.GetMainFrame().ExecuteJavaScriptAsync("const element = document.createElement('textarea'); element.value = document.getElementsByClassName('question-text')[0].innerText; document.body.appendChild(element); element.select(); document.execCommand('copy'); document.body.removeChild(element);");
        
        Clipboard.ContainsText(TextDataFormat.Text);
        string questionfromclipboard = Clipboard.GetText(TextDataFormat.Text);
        MessageBox.Show(questionfromclipboard.ToString());
        File.AppendAllText(@"C:UsersRenoPCDesktopNew Questions.txt", questionfromclipboard + Environment.NewLine);

Answer

Here, try this:

CurBrowser.GetMainFrame().ExecuteJavaScriptAsync("var element = document.createElement('textarea'); element.value = document.getElementsByClassName('question-text')[0].innerText; document.body.appendChild(element); element.select(); document.execCommand('copy'); document.body.removeChild(element);");
Thread.Sleep(500);
Clipboard.ContainsText(TextDataFormat.Text);
string questionfromclipboard = Clipboard.GetText(TextDataFormat.Text);
MessageBox.Show(questionfromclipboard.ToString());
File.AppendAllText(@"C:UsersRenoPCDesktopNew Questions.txt", questionfromclipboard + Environment.NewLine);