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

128
Vistas
nodejs selenium add a function to webdriver (highlight element) click() is not a function

trying to create a new function in chromedriver or override existing findelement() function

First steps for me was create new instead of override to test it

 const driver = await new Builder()
  .forBrowser("chrome")
  .setChromeOptions(
      new chrome.Options()
          .windowSize(screen)
          )
  .build();
  driver.findElementWithHighlight = async (locator) => {
    let element = await driver.findElement(locator);
    await driver.executeScript("arguments[0].style.border='3px solid red'", element);
    return driver.findElement(locator);
  };

then in another function I call

await driver.findElementWithHighlight(some locator).click();

but after all this I get this error:

TypeError: driver.findElementWithHighlight(...).click is not a function

What do I do wrong here? Why my new function do not have click() method if it returns same WebElementPromise?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

It returns a promise and you are calling the .click() on the Promise object. Instead wrap it around (await driver.findElementWithHighlight(...)).click(). So It will be awaited and you will be able to call your click function.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can keep making more functions

driver.findElementWithHighlight = async (locator) => {
    let element = await driver.findElement(locator);
    await driver.executeScript("arguments[0].style.border='3px solid red'", element);
    return driver.findElement(locator);
};
driver.findElementWithHighlightAndClick = async (locator) => {
    return driver.findElementWithHighlight(locator)
        .then((highlighted) => {
            return highlighted.click();
        });
};

driver.findElementWithHighlightAndClick(some_locator);
about 4 years ago · Juan Pablo Isaza Denunciar
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