I am facing a challenge where I have an HTML document stored in memory as a string, and it includes a <script>
tag with a script that manipulates the DOM. My goal is to load this HTML page into Selenium WebDriver and retrieve the modified version after the script has taken effect. However, I am reluctant to write the HTML to a file and then load it using
driver.get("file://path/to/file")
. So, my question is whether there is another way to achieve this without writing to a file.
If WebDriver cannot handle this task, are there any alternative solutions available?
Let's consider the following example:
<html><head>
<script type="text/javascript">
function fill(){
var i = "secret"
document.forms[0].elements[1].value=i
}
</script>
</head><body onload="fill()">
<form method="POST"><input type="hidden" name="he1" value="">
<input type="hidden" name="he2" value="">
</form></body></html>
The desired outcome is for the WebDriver to execute the script and update the form accordingly.
Note: The provided example is simplified; the actual script I need to run is much more complex.