2

Let me explain what is the issue.

I am new here so please ignore my mistakes. I will try my best to explain myself.

I am having a webpage.html and I included a js script like from script or may be inside <script> tag.

I saved something like var v ="my variable from a text box" inside the webpage.

Now I want the var v value from the console to view the value of it.

I tried:

nightmare.evaluate(function () {
// now we're executing inside the browser scope.
return window.YOUR_VARIABLE;
}).then(function(YOUR_VARIABLE) {
// use the value
})

Did not worked for me.

The javascript is loading during the using process in webpage and the script is :

initAvlFareEnq(e) {
                var t = 0;
                (Array.isArray(e.avlFareResponseDTO) ? e.avlFareResponseDTO : Array.of(e.avlFareResponseDTO)).forEach(e=>{
                    if (null == e.errorMessage && null == e.errorMessage) {
                        e.avlDayList = Array.isArray(e.avlDayList) ? e.avlDayList : Array.of(e.avlDayList);
                        
                        this.multiLapJourneyDetails.lapDetails.push(i)
                    } else
                        this.messageService.add({
                            life: this.langService.life,
                        })
                }
                ),
                this.multiLapJourneyDetails.mainJourneyTxnId = this.jpInput.txnId,
                this.multiLapJourneyDetails.clientTxnId = (new Date).getTime().toString(36),
                
            }

I want this.multiLapJourneyDetails.clientTxnId value when its get executed

jay kishan
  • 82
  • 1
  • 7

2 Answers2

0

If you have an html page and you put a variable called v inside a script block, you can see that variable opening the console and simply writing v because your variable is in window scope.

Of course you can also add a console.log(v) statement in your script block, after the declaration of v, in order to see his value automatically when you open the console.

Marco Nisi
  • 1,211
  • 10
  • 13
0

Inside the webpage, do window.myVar = "some value" instead of var myVar = "some value".

nightmare.evaluate(function () {
    return window.myVar;
}).then(function(myVar) {
    // do something here
})
user1280483
  • 470
  • 4
  • 11