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

138
Visualizações
Attribute of an element is outputting null

As part of my nightwatchjs testing, what I would like to do is get the attribute of an element, then set this attribute value to a different value.

Here is the HTML snippet;

enter image description here

So first of all I'd like to get the value of the data-page-view-threshold attribute, which should be '3' and output this so I know I'm interacting with the correct element.

Currently, my code looks like this;

module.exports = {
    'Navigate to an homepage': function (browser, document) {
        browser.url(browser.launch_url);
        browser.pause(5000);
        browser.execute(function() {
            return document.getElementById('#newsletterSignup').getAttribute('data-page-view-threshold');
        }, [ ], function callback(result) {
                    console.log('Result from execute', result);
        });
    },
    'Closing the browser': function (browser)  {
        browser.browserEnd();
    },
};

However, when I run this I get the following error;

Error while running .executeScript() protocol action: An error occurred while executing user supplied JavaScript. – javascript error: Cannot read properties of null (reading ...

Result from execute {
  status: -1,
  state: '',
  code: '',
  value: {
    message: "javascript error: Cannot read properties of null (reading 'getAttribute')",
    error: [
      '  (Session info: chrome=95.0.4638.69)',
      '  (Driver info: chromedriver=95.0.4638.54 (d31a821ec901f68d0d34ccdbaea45b4c86ce543e-refs/branch-heads/4638@{#871}),platform=Mac OS X 11.6.1 x86_64)'
    ]
  },
  errorStatus: 17,
  error: 'An error occurred while executing user supplied JavaScript. – javascript error: Cannot read properties of null (reading ...',
  httpStatusCode: 200
}

I thought that this would get the value of '3' from the data-page-view-threshold attribute, but it returns a null.

Am I using the correct code to 'extract' this attribute, or is there something obvious that I'm doing wrong with this? Thanks

about 4 years ago · Juan Pablo Isaza
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