Method Contains different from GetText

Method Contains different from GetText

Home Forums Ask Expert Method Contains different from GetText

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #32187
    Gabriel Fiel
    Participant

      Hi

      I am facing a problem, when I use method .Contains(), ZAPTEST recognize the number with a white space, example: “20123. 123”.
      When I use .GetText it gets it correctly: “20123.123”.
      So I tried creating a variable with GetText, and apply .Contains, but it didn’t work.

      Is there a way to ignore white spaces when I use Contains or maybe another solution?
      Thank you.

      Have a good weekend.

      #32188
      Kirill Bulatnikov
      Participant

        Hello gabriel.fiel. Thanks for using ZAPTEST.

        I think VB Script function “replace” will help you! You need to replace possible spaces (” “) with null (“”) and then you can compare the content.

        Hope that helps.

        Thanks,
        Kirill.
        ZAPTEST Team.

        #32189
        Gabriel Fiel
        Participant

          Hi Kirill

          I am using javascript, so I tried Zap.Common.ReplaceSubString:

          var myVar= Zap.Common.ReplaceSubString(Application("My app").View("My View").Object("Text").GetText(), " ", "");

          if (myVar.Contains("20123.123")) {
          }

          I also tried this one:

          var myVar = Application("My app").View("My Viiew").Object("Text").GetText();
          var newVar = myVar.replace(" ", "");

          if (newVar.Contains("20123.123")) {
          }

          But it is not working, it shows an error when I try to use method Contains() with the variable (“O objeto não da suporte para a propriedade ou método”).
          Can you help me?

          Thank you.

          #32190
          Kirill Bulatnikov
          Participant

            Hey Gabriel
            First of all I have to admit that you are using GetText method improperly – to grab some text from the object you need to have real parent object for it otherwise ZAPTEST will not know where get text from and you will get empty value. And as soon as the value is null Contains method may output an error.

            Hope that helps.
            Thanks,
            Kirill.
            ZAPTEST Team

            #32191
            Gabriel Fiel
            Participant

              It was an example of how I am using it.
              I am using .Object(“parent”).Object(“son”).GetText() in the script.
              I get the text from the object, it is there, working.

              The problem here is with method Contains(), because in the documentation they use it with an object: Object(“x”).Contains(“something”).
              I am trying to use a variable instead: myVariable.Contains(“something”), is there a similar solution to solve this?

              Thank you 🙂
              Bye

            Viewing 5 posts - 1 through 5 (of 5 total)
            • You must be logged in to reply to this topic.

            Virtual Expert

            ZAPTEST

            ZAPTEST Logo