2

In one of my test case I hit the rest API using restAssured and the API always returns the response in pure HTML. The returned HTML is basically the source of a valid page. Now I can't use webDriver.get(URL); method since I don't have a direct URL.

Does selenium provide any such method in which I can open the HTML source directly in the browser instead of providing a URL?

  • I am not able to understand the why would you need webdriver methods in rest assured. Your problem statement is not very clear. Can you rephrase it. – demouser123 Sep 26 '17 at 12:26
4

The basic idea is to just open a blank page and then set the inner HTML of the current page:

String innerHtml = "your HTML here";
driver.executeScript("document.innerHTML = " + innerHtml);

Or, you can also save that HTML into a file and then open the file via file:// protocol:

driver.get("file://path/to/file.html")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.