1

I'm using Selenium with Java for some tests. The code I have to print the pages html from javascript works great as an alert:

js.executeScript("alert($('html').html());");

However when I use return, nothing prints in the Eclipse console:

js.executeScript("return $('html').html();");

What am I doing wrong, and how can i print (using System.out.print) the html result from returning in Javascript? Thanks, and no I do not want to use source.

2
  • 2
    What happens if you assign a value to the js.executeScript invocation and print the value? (ie, System.out.println(js.executeScript(..))) Commented Aug 8, 2014 at 22:33
  • Glad to hear! The issue may be that the contents are indeed being returned but were not handled appropriately (ie, not printing via the System.out.println invocation). Commented Aug 8, 2014 at 22:43

1 Answer 1

2

You can use driver.getPageSource() to get the result you want, I believe.

System.out.println(driver.getPageSource());
Sign up to request clarification or add additional context in comments.

1 Comment

I know i said I don't want to use source in question, but this actually works for the parts of the page I was trying to retrieve, thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.