I am facing a challenge when trying to insert a large HTML code (around 3000 letters) into a Textarea. Using .sendkeys
is too slow for this task, so I turned to JavaScript with Selenium and it worked well until I encountered issues while adding the HTML code itself. Here's my current code:
public void AttributeSet(string id, string value) {
IJavaScriptExecutor js = (IJavaScriptExecutor)browser;
js.ExecuteScript("document.getElementById(\"" + id + "\").value = ('" + value + "');");
}
I found that this code works fine for single-line strings, but struggles with multiline strings and strings containing quotes ""
.
Due to the presence of numerous quotes in HTML code, I keep encountering obstacles. I have attempted various solutions such as replacing newlines with \n
, and quotes with \"
, among other things.
Is there a simpler way to achieve this task? If there is, I would greatly appreciate any guidance you can offer. Thank you!