Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
164
rated 0 times [  165] [ 1]  / answers: 1 / hits: 32966  / 10 Years ago, thu, march 20, 2014, 12:00:00

I have a html document in memory as a string. It contains a <script> tag with a little script that manipulates the dom. I now want to load that html page into selenium webdriver and get back the page after the script manipulates it. Since I have the html already in memory, I don't like the idea much of writing the html into a file and load it as file with driver.get(file://path/to/file). So the question is, if there is a possibility to achieve what I want.



IF webdriver can't do it, maybe there is a possibility other than that?



Here comes an 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>


Obviously, I want the webdriver to perform the dom manipulation and change the form according to the script.



Note this is just an example. The actual script I need to run does much more complicated things.


More From » java

 Answers
14

this code can load any html string which include js and css.


html_bs64 = base64.b64encode(innerHtml.encode('utf-8')).decode()
driver.get("data:text/html;base64," + html_bs64)

[#71883] Wednesday, March 19, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aleenamarinr

Total Points: 610
Total Questions: 109
Total Answers: 118

Location: Mayotte
Member since Mon, Sep 12, 2022
2 Years ago
;