Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

213
Visualizações
Get variable value from supplied js page in the console in JavaScript

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

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

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.

about 4 years ago · Juan Pablo Isaza Relatório

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
})
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda