0

I need to extract a javascript value of a variable from a web page.

I think there is a way if I can make nightmarejs to go to the page, open the dev tool, type in the variable to the javascript console and return the output.

I'm comfortable with making nightmarejs client to go to the page, click necessary buttons et cetera. But, I don't know how to type in the console and return the output, if possible.

Any suggestion is appreciated.

4
  • 1
    Any chance you could share the code you've tried already? It's much easier for others to assist. Thanks! Commented Mar 22, 2017 at 17:58
  • Since I don't know how to type in the console and return the output with nightmare I haven't tried anything. This is the only solution comes to my mind which I don't know how to do. Commented Mar 22, 2017 at 18:07
  • I'm willing to attempt to code that, if you don't mind sharing more details, like the website you want to interact with and the variable you want to read. Commented Mar 22, 2017 at 19:05
  • 1
    I've solve the problem with the help of the answer below. Thanks @Helvio Commented Mar 23, 2017 at 10:34

1 Answer 1

4

You can use evaluate to run code on the page.

nightmare.evaluate(function () {
    // now we're executing inside the browser scope.
    return window.YOUR_VARIABLE;
}).then(function(YOUR_VARIABLE) {
    // use the value
})
Sign up to request clarification or add additional context in comments.

1 Comment

Always returning document.body.innerHTML narrowed my view I guess. 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.