I have a html string (can not write it to file) in memory, I want to render the html string in Selenium remote webdriver and take the screenshot. Following is the code i used
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:9515"), capabilities);
driver.get("about:blank");
((JavascriptExecutor) driver)
.executeScript("arguments[0].innerHTML='" + StringEscapeUtils.escapeHtml3(_html) + "'");
The problem with this approach is, it is breaking the java script execution because of the new line character or some other characters and getting the below error
{"errorMessage":"Unexpected EOF","request":{"headers":{"Accept-Encoding":"gzip,deflate","Connection":
I got the log error message so i have pasted only certain portion of it.
I have looked into this in SO but it did not help me much.
Can you please help me to solve this? My question is i want to load the html string in selenium driver and take the screenshot.
Assuming _html
is your html string, it should be along the lines of:
driver.executeScript('document.body.innerHTML = arguments[0]', _html)
You shouldn't need to escape quotes or newlines.
To open in the dynamic URL in the same TAB you can use:
driver.get("about:blank");
((JavascriptExecutor) driver).executeScript("window.location.replace(" + StringEscapeUtils.escapeHtml3(_html) + ");");
To open in the dynamic URL in a new TAB you can use:
driver.get("about:blank");
((JavascriptExecutor) driver).executeScript("window.open('" + StringEscapeUtils.escapeHtml3(_html) +"');");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.