Asserting text of element with &nbsp











up vote
2
down vote

favorite












I need to check the text of a Div tag and ensure if it is showing the correct text of not



here is the HTML Code:



HTML Tag



Here is the step definition i wrote to assert the content



    Given(/^offer summary section should display "([^"]*)" amount against "([^"]*)"$/, (charge, labelText) => {
const parentElement = cy.get('.c-offer-summary > .c-offer-summary__ledger').children('.c-ledger__section').find('.c-ledger__row-name').contains(labelText).parent();
parentElement.find('.c-ledger__row-amount').invoke('text').should('eq',charge);
});


But cypress is throwing an error:



Error



I am not sure where i am going wrong !!! :(



any help is appreciated










share|improve this question




























    up vote
    2
    down vote

    favorite












    I need to check the text of a Div tag and ensure if it is showing the correct text of not



    here is the HTML Code:



    HTML Tag



    Here is the step definition i wrote to assert the content



        Given(/^offer summary section should display "([^"]*)" amount against "([^"]*)"$/, (charge, labelText) => {
    const parentElement = cy.get('.c-offer-summary > .c-offer-summary__ledger').children('.c-ledger__section').find('.c-ledger__row-name').contains(labelText).parent();
    parentElement.find('.c-ledger__row-amount').invoke('text').should('eq',charge);
    });


    But cypress is throwing an error:



    Error



    I am not sure where i am going wrong !!! :(



    any help is appreciated










    share|improve this question


























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I need to check the text of a Div tag and ensure if it is showing the correct text of not



      here is the HTML Code:



      HTML Tag



      Here is the step definition i wrote to assert the content



          Given(/^offer summary section should display "([^"]*)" amount against "([^"]*)"$/, (charge, labelText) => {
      const parentElement = cy.get('.c-offer-summary > .c-offer-summary__ledger').children('.c-ledger__section').find('.c-ledger__row-name').contains(labelText).parent();
      parentElement.find('.c-ledger__row-amount').invoke('text').should('eq',charge);
      });


      But cypress is throwing an error:



      Error



      I am not sure where i am going wrong !!! :(



      any help is appreciated










      share|improve this question















      I need to check the text of a Div tag and ensure if it is showing the correct text of not



      here is the HTML Code:



      HTML Tag



      Here is the step definition i wrote to assert the content



          Given(/^offer summary section should display "([^"]*)" amount against "([^"]*)"$/, (charge, labelText) => {
      const parentElement = cy.get('.c-offer-summary > .c-offer-summary__ledger').children('.c-ledger__section').find('.c-ledger__row-name').contains(labelText).parent();
      parentElement.find('.c-ledger__row-amount').invoke('text').should('eq',charge);
      });


      But cypress is throwing an error:



      Error



      I am not sure where i am going wrong !!! :(



      any help is appreciated







      mocha chai cypress






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 19 hours ago









      Brendan

      577314




      577314










      asked Nov 19 at 16:02









      Venkata

      899




      899
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          I assume you are trying to to test that .c-ledger__row-amount is "DKK 15.00". Try this.



          cy.get(".c-ledger__row-amount").invoke('text').then((text) => {
          expect(text.trim()).equal('DKK 15.00');
          });


          Sometimes you have to remove the trailing spaces






          share|improve this answer




























            up vote
            0
            down vote













            This looks like a similar problem to Replacing "&nbsp" from javascript dom text node.



            Please try this command chain



            const parentElement = cy.get('.c-offer-summary > .c-offer-summary__ledger')
            .children('.c-ledger__section')
            .find('.c-ledger__row-name')
            .contains(labelText)
            .parent();

            parentElement.find('.c-ledger__row-amount')
            .invoke('text')
            .should('satisfy', (text) => text.replace(/u00a0/g, ' ') === charge);





            share|improve this answer





















              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














               

              draft saved


              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378473%2fasserting-text-of-element-with-nbsp%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              0
              down vote













              I assume you are trying to to test that .c-ledger__row-amount is "DKK 15.00". Try this.



              cy.get(".c-ledger__row-amount").invoke('text').then((text) => {
              expect(text.trim()).equal('DKK 15.00');
              });


              Sometimes you have to remove the trailing spaces






              share|improve this answer

























                up vote
                0
                down vote













                I assume you are trying to to test that .c-ledger__row-amount is "DKK 15.00". Try this.



                cy.get(".c-ledger__row-amount").invoke('text').then((text) => {
                expect(text.trim()).equal('DKK 15.00');
                });


                Sometimes you have to remove the trailing spaces






                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  I assume you are trying to to test that .c-ledger__row-amount is "DKK 15.00". Try this.



                  cy.get(".c-ledger__row-amount").invoke('text').then((text) => {
                  expect(text.trim()).equal('DKK 15.00');
                  });


                  Sometimes you have to remove the trailing spaces






                  share|improve this answer












                  I assume you are trying to to test that .c-ledger__row-amount is "DKK 15.00". Try this.



                  cy.get(".c-ledger__row-amount").invoke('text').then((text) => {
                  expect(text.trim()).equal('DKK 15.00');
                  });


                  Sometimes you have to remove the trailing spaces







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 20 at 14:32









                  Maccurt

                  8461718




                  8461718
























                      up vote
                      0
                      down vote













                      This looks like a similar problem to Replacing "&nbsp" from javascript dom text node.



                      Please try this command chain



                      const parentElement = cy.get('.c-offer-summary > .c-offer-summary__ledger')
                      .children('.c-ledger__section')
                      .find('.c-ledger__row-name')
                      .contains(labelText)
                      .parent();

                      parentElement.find('.c-ledger__row-amount')
                      .invoke('text')
                      .should('satisfy', (text) => text.replace(/u00a0/g, ' ') === charge);





                      share|improve this answer

























                        up vote
                        0
                        down vote













                        This looks like a similar problem to Replacing "&nbsp" from javascript dom text node.



                        Please try this command chain



                        const parentElement = cy.get('.c-offer-summary > .c-offer-summary__ledger')
                        .children('.c-ledger__section')
                        .find('.c-ledger__row-name')
                        .contains(labelText)
                        .parent();

                        parentElement.find('.c-ledger__row-amount')
                        .invoke('text')
                        .should('satisfy', (text) => text.replace(/u00a0/g, ' ') === charge);





                        share|improve this answer























                          up vote
                          0
                          down vote










                          up vote
                          0
                          down vote









                          This looks like a similar problem to Replacing "&nbsp" from javascript dom text node.



                          Please try this command chain



                          const parentElement = cy.get('.c-offer-summary > .c-offer-summary__ledger')
                          .children('.c-ledger__section')
                          .find('.c-ledger__row-name')
                          .contains(labelText)
                          .parent();

                          parentElement.find('.c-ledger__row-amount')
                          .invoke('text')
                          .should('satisfy', (text) => text.replace(/u00a0/g, ' ') === charge);





                          share|improve this answer












                          This looks like a similar problem to Replacing "&nbsp" from javascript dom text node.



                          Please try this command chain



                          const parentElement = cy.get('.c-offer-summary > .c-offer-summary__ledger')
                          .children('.c-ledger__section')
                          .find('.c-ledger__row-name')
                          .contains(labelText)
                          .parent();

                          parentElement.find('.c-ledger__row-amount')
                          .invoke('text')
                          .should('satisfy', (text) => text.replace(/u00a0/g, ' ') === charge);






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Nov 20 at 18:56









                          Hiram K. Hackenbacker

                          1536




                          1536






























                               

                              draft saved


                              draft discarded



















































                               


                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53378473%2fasserting-text-of-element-with-nbsp%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Tonle Sap (See)

                              I get strange results when I access the Sqlitedatabase with Unity C# via XAMPP

                              Guatemaltekische Davis-Cup-Mannschaft