Forum Discussion

nedbacan's avatar
nedbacan
Frequent Contributor
2 years ago

How to separate the Inner Text into individual variables

Hello.  If someone can show me how to separate the Inner Text into individual variables.

Using the Spy tool, I am able to get the innerText, in this case it is a Store name, the ID and address but all in one.

I checked the other properties, it does not identify it separately.  I image it's how the GUI has it displayed.

 

To work around it, Is it possible to separate the content found in the innerText,  The information data are separated by common. 

 

For instance, 

StoreFullName = Aliases.browser.pageStoreX.FindElement("#current-store").innerText
Log.Message(StoreFullName);

 

Displays the full name:  VisionOne, ID:12345678, One Main St. 

 

But I would like to split each field into separate variables, Is it possible? 

 

Log.Message(Store_Name) will display "VisionOne"

Log.Message(Store_ID) will display "12345678"

Log.Message(Store_Address) will display "One Main St. "

 

Screen shot of the example of the CSS , xpath copy is //*[@id="current-store"]/div[2]/div[2]/text()[1]

 

 

  • If it's comma seperated, then you can do something like this

    function Split()
    {
        var str = "VisionOne, ID:12345678, One Main St.";
        const arr = str.split(",");
        for (var i = 0; i < arr.length; i++) {
            Log.Message(arr[i]);
        }    
    }
  • rraghvani's avatar
    rraghvani
    Champion Level 3

    If it's comma seperated, then you can do something like this

    function Split()
    {
        var str = "VisionOne, ID:12345678, One Main St.";
        const arr = str.split(",");
        for (var i = 0; i < arr.length; i++) {
            Log.Message(arr[i]);
        }    
    }
  • nedbacan's avatar
    nedbacan
    Frequent Contributor

    Using your example, how can I add each string to a variable?  Right now, I get each string in the message but how will I pass each message into a global variable