Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

140
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda