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

135
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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