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

161
Views
Angular2 E2E Protractor. Wait until element has class

I need find a way to wait with my e2e test (angular2 project) until the tested element gets an specific css class.

Is there any possible way without browser.wait() or browser.sleep()?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You've even used the word "wait" in the question, but asking to solve it without the built-in waiting functions. I don't see much sense in that.

We've solved something similar before and came up with a custom wait function which can be used as an Expected Condition with browser.wait():

function waitForCssClass(elementFinder, desiredClass) {
    return function () {
        return elementFinder.getAttribute('class').then(function (classValue) {
            return classValue && classValue.indexOf(desiredClass) >= 0;
        });
    };
};

browser.wait(waitForCssClass($("#myid"), "desiredClass"), 5000);
over 4 years ago · Santiago Trujillo Report

0

This function waits for a class to disappears from an element, given the element object (ElementFinder) and the CSS class you want to check for.

    static async waitCssClassToDisappear(elem:ElementFinder, cssClass:string, timeout?: number) {
        await browser.wait(()=>{
            return elem.getAttribute('class').then((value) =>{
                return value.indexOf(cssClass) < 0;
            });
        }, timeout ? timeout : Utils.defaultTimeout, 'CSS class did not disappear within specified timeout');
    }

over 4 years ago · Santiago Trujillo 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!