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

260
Views
Getting Promise Pending in selenium for a web element used in an assertion

I am just trying to run a simple test using selenium with chai library for assertion. Webdriver executes a script to set a token for login. I can see on the UI that it login fine but the test fails on the assertion with web element status being promise pending. Any idea what am i missing here. thanks!

Here is the piece of code

const {Builder, By, Key, until} = require('selenium-webdriver');
let chai = require('chai');
let expect = chai.expect;
require('chromedriver');

(async function example() {
    let driver = await new Builder().forBrowser('chrome').build();
        await driver.get('http://localhost:4200/login');
        driver.executeScript('window.localStorage.setItem("token", "xyz");');
        driver.executeScript('window.localStorage.setItem("lastAction", "' + Date.now() + '");');
        await driver.wait(until.titleIs('XXXX'), 1000);
        expect(driver.findElement(By.id('welcome-header')).getText()).to.equal('ZZZZZ');

})();

And below is the error what i get

expect(driver.findElement(By.id('welcome-header')).getText()).to.equal('ZZZZZ');
                                                                         ^
AssertionError: expected {} to equal 'ZZZZZ'
    at example (******\e2e-spike-copy\tests\login_test_copy.js:13:74)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  showDiff: true,
  actual: Promise { <pending> },
  expected: 'ZZZZZ',
  operator: 'strictEqual'
}

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

driver.findElement() is an asynchronous function, so you have to await for it to resolve, just as you do for other things.

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!