• Login
    • Login
      • Login
      • DEVHIDE
        • Home (current)
        • About
        • Contact
        • Cookie
        • Home (current)
        • About
        • Contact
        • Cookie
        • Disclaimer
        • Privacy
        • TOS
        Login Or Sign up

        Check condition related to child element while traversing parents - Protractor

        114 Views Asked by suat At 31 August 2020 at 16:50 2025-11-28T02:07:21.120000

        I have an HTML snippet as follows:

        ...
        <div class="show-div account">
          <ul >
            <li>
              <a href="/account/login">Login</a>
            </li>
            <li>
              <a href="/account/register">Register</a>
            </li>
          </ul>
        </div>
        ...
        

        I'd like to check whether the login page is clicked once the Login button is clicked. What I understood from the docs, the following should work but it won't.

            const loginAction = await accountIcon.element(by.className('show-div')).$('ul').$$('li').filter(async function(elem) {
              const a = elem.element(by.css('a'));
              const attr = await a.getAttribute('href');
              return attr.includes('/account/login');
            }).first().$('a');
            await loginAction.click();
            const url = await browser.getCurrentUrl();
            expect(url).endsWith('/account/login');
        

        I'm using "protractor": "7.0.0" with Angular 10. Those are auto-generated by the JHipster framework. I'm not sure whether I need to use async/await mechanism. Considering the ElementFinder API, I should but most of the examples do not utilize it.

        (BTW, SELENIUM_PROMISE_MANAGER is disabled)

        I'd appreciate any help. Thanks in advance.

        javascript angular protractor jhipster angular-e2e
        Original Q&A
        1

        There are 1 best solutions below

        0
        Sergey Pleshakov Sergey Pleshakov On 01 September 2020 at 12:50 BEST ANSWER

        Your first problem could have been your locator. Filtering could not work, then chaining may have problems, element...element.all...first().element()

        If the url is static you can use that as locator, and avoid all this

        let elem = $('[href="/account/login"]')

        Second possible problem, after you click, you may need to wait. Otherwise getCurrentUrl may return the original url since it hasn't loaded the new page yet. In this case I can recommend you to wait for that url

        var EC = protractor.ExpectedConditions;
        // Waits for the URL to contain 'foo'.
        await browser.wait(EC.urlContains('/account/login'), 15000);
        

        In this part of the script, if url is never present it will fail with explicit error, saying this url wasn't present. Otherwise, you don't need to assert the url. If the script passed, this may serve you as a warant that the url is there, no need to assert it

        Related Questions in JAVASCRIPT

        • Angular Show All When No Filter Is Supplied
        • Why does a function show up as not defined
        • I count the time the user takes to solve my quiz using Javascript but I want the same time displayed on another page
        • Set "More" "Less" font size
        • Using pagination on a table in AngularJS
        • How to sort these using Javascript or Jquery Most effectively
        • how to fill out the table with next values in array with one button
        • State with different subviews
        • Ajax jQuery firing multiple time display event for the same result
        • Getting and passing MVC Model data to AngularJS controller
        • Disable variable in eval
        • javascript nested loops waiting for user input
        • .hover() seems to overwrite .click()
        • How to sort a multi-dimensional array by the second array in descending order?
        • How do I find the fonts that are not loading in a CORS situation ( MoovWeb )?

        Related Questions in ANGULAR

        • Is it possible to use ES5 JavaScript with Angular 2 instead of TypeScript?
        • Module '"angular2/angular2"' has no exported member 'For'
        • import syntax in typescript creating another js file in visual studio
        • Separate ts file for imports
        • How to use an AngularJS 2 component multiple times in the same page?
        • injectables not working in angular 2.0 latest build 26
        • Does angular2 bootstrap have a way to dynamically target elements like it does in angular 1.x
        • Import {} from location is not found in VS Code using TypeScript and Angular 2
        • Angular 2/Typescript: require not found
        • ng-switch in Angular2
        • Angular 2 import issue: "Zone already exported on window the object!"
        • How to make FileReader work with Angular2?
        • Writing the most basic Unit test in Angular 2?
        • Angular2: Creating child components programmatically
        • AngularJS - TypeError: Cannot read property 'canonicalUrl' of undefined

        Related Questions in PROTRACTOR

        • Protractor did not run properly when using browser.wait, msg: "Wait timed out after XXXms"
        • Getting the button text in Protractor
        • MSSQL - Nodejs - Undefined is not a function issue
        • Load additional CONFIG file with values
        • Protractor, login to asp,net MVC login page, wait for default page then , redirect to angular page and do tests....how?
        • Phantomjs fails when Protractor is run with selenium hub
        • Protractor Test Result variations
        • How to use Jasmine and CucumberJS with Protractor
        • Protractor : Failed: Object has no method 'getText'
        • Protractor - How to get first or last CHILD value
        • Protractor : Refreshing browser instance between testsuites
        • Protractor e2e tests with MEANJS navigation
        • Protractor: Multiple browser instance tests fail where Single Instance tests pass
        • cucumber-js and Chai how to expect if element with given selector exist in DOM
        • How to use isElementPresent/isPresent inside ng-repeat in protractor?

        Related Questions in JHIPSTER

        • Importing jHipster projects into intellij
        • What is the best and fastest way to clean-up traces of JHipster?
        • Failed to decode downloaded font on Heroku
        • How JHipster rename resources files
        • JHipster: REST URL mapping for Account
        • Deploying a JHipster/MongoDB application to Heroku
        • Integrate new menu for admin
        • ElasticSearch nested object query
        • JHipster MailService - javax.mail.SendFailedException: No recipient addresses
        • How to use Textangular with Jhipster
        • Error when create jhipster sample 21-points application
        • Generate Value Object (Not Entity) with JDL studio
        • JHipster configure maven wrapper proxy
        • Getting error while running "yo jhipster-ionic"
        • Use api in Jhipster from Angularjs

        Related Questions in ANGULAR-E2E

        • Angular CLI - ng e2e throws error
        • Can not run ng e2e in Ubuntu (Digital Ocean)
        • Mocking rest calls in functional e2e protractor tests in angular 4 project
        • Test an element is in viewport with protractor
        • Protractor - wait X seconds while page loading, if still not loaded - click button again
        • E2E Angular application for slow network 3g slow using Protractor
        • Ag-grid access and edit cell from Protractor e2e tests
        • Prevent Protractor from compiling angular code
        • Angular e2e fails with 'Angular can't be found' because of Redux enhancer?
        • E2e testing doing nothing since upgrade to ng7
        • angular ng e2e testcase with file download not working with headless chrome
        • How to inject services in e2e testing angular (protractor)
        • e2e testing angular 7: Failed: Cannot read property 'fetchData' of undefined
        • angular e2e testing : how to test Service inject(use) another services
        • Protractor test hangs on await browser.wait with disabled control flow

        Trending Questions

        • UIImageView Frame Doesn't Reflect Constraints
        • Is it possible to use adb commands to click on a view by finding its ID?
        • How to create a new web character symbol recognizable by html/javascript?
        • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
        • Heap Gives Page Fault
        • Connect ffmpeg to Visual Studio 2008
        • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
        • How to avoid default initialization of objects in std::vector?
        • second argument of the command line arguments in a format other than char** argv or char* argv[]
        • How to improve efficiency of algorithm which generates next lexicographic permutation?
        • Navigating to the another actvity app getting crash in android
        • How to read the particular message format in android and store in sqlite database?
        • Resetting inventory status after order is cancelled
        • Efficiently compute powers of X in SSE/AVX
        • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

        Popular # Hahtags

        javascript python java c# php android html jquery c++ css ios sql mysql r reactjs

        Popular Questions

        • How do I undo the most recent local commits in Git?
        • How can I remove a specific item from an array in JavaScript?
        • How do I delete a Git branch locally and remotely?
        • Find all files containing a specific text (string) on Linux?
        • How do I revert a Git repository to a previous commit?
        • How do I create an HTML button that acts like a link?
        • How do I check out a remote Git branch?
        • How do I force "git pull" to overwrite local files?
        • How do I list all files of a directory?
        • How to check whether a string contains a substring in JavaScript?
        • How do I redirect to another webpage?
        • How can I iterate over rows in a Pandas DataFrame?
        • How do I convert a String to an int in Java?
        • Does Python have a string 'contains' substring method?
        • How do I check if a string contains a specific word?
        .

        Copyright © 2021 Jogjafile Inc.

        • Disclaimer
        • Privacy
        • TOS
        • Homegardensmart
        • Math
        • Aftereffectstemplates