Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!