Forum Discussion

Vivek72's avatar
Vivek72
Contributor
12 years ago

How to search for quoted strings

Hi 



I am looking for a method to find all the strings on a web page that's either single quoted or double quoted. The application is built in Silverlight and solution in vbscript for any condition if applicable would be an easy  understanding for me. thanks a lot

7 Replies

  • AlexKaras's avatar
    AlexKaras
    Icon for Champion Level 1 rankChampion Level 1
    Hi,



    The first obvious solution is to use the .innerText property of the page to get all text from the page and then process it with the regular expression like this (untested, off-top of my head):

    (['"]?)(\.+)\1



    (Not sure at the moment how to handle apostrophes)
  • Hi Alexei,



    Thanks a lot for your reply. Tried and below regular expression works for me:

    " ( ' [ ^ ' ] * ' ) " . The issue for me now is .innerText property. The innerText property value is Null for my application object although I can get innerText values for other web pages. I have tried changing Current project Tree models (blind try) but still couldn't manage to get innerText values. Also, If I can get any sample code then that would be of great help.



    Tried below code where InStr is NullValue in my object browser:



    InStr = Sys.Browser.Page(URL).Form("form1").innerText

    Set regEx = New RegExp

    regEx.Pattern = "('[^']*')"

    regEx.Global = True

    Set Matches = regEx.Execute(InStr)

    For Each Match in Matches

    ResStr = ResStr & Match.Value

    Next

    Log.Message(ResStr)




    Thanks







     


  • AlexKaras's avatar
    AlexKaras
    Icon for Champion Level 1 rankChampion Level 1
    Hi,



    Why not just to check if innerText is null?

    E.g.:

    InStr = Sys.Browser.Page(URL).Form("form1").innerText

    If (InStr Is Null) Then _

      InStr = ""

    Set regEx = New RegExp

    ...
  • Hi Alex,



    Unfortunately, this doesn't work. Error says 'InStr' is an illegal assignment.

    Object browser  also not showing any details of  contentText or  document  properties of the Sys.Page or Sys.Page.Panel objects. Any other techniques that can be of help?



    Thanks
  • AlexKaras's avatar
    AlexKaras
    Icon for Champion Level 1 rankChampion Level 1
    Hi,



    >  Error says 'InStr' is an illegal assignment

    This is correct because InStr is the name of the VBScript's function and it is not possible to assign the value to the function in VBScript.

    Try to change the name to, say, sInStr.
  • Hi Alex,



    That does work but that doesn't solve the issue because when 'InStr' value is Null, it means Test Complete is saying there is no text on the page which is wrong in my case, or it is not recognising the text and so when I run above script it returns log which returns empty  'ResStr' & 'InStr' values. In my case there is Text in the page and also holds quoted strings. I tried same script on other websites and it works fine giving me InStr values on my log.

    Thanks a lot.


  • I want to Execute a regular expression search against all object names on a web page and post those collection of Matches to log. Earlier, I was adviced to look for "contentDocument" and "innerText" properties of my application but because those properties doesnt show any values in my Object browser I cant use them. I used find method but it finds just one object in object browser that contains regular expression and posts it to log whereas I want all the objects on a webpage to be idenfied regardless of which property holds that string. Any workaround on this or even if different method to solve the issue is most welcome. Thanks for any comment.