Forum Discussion

Gill's avatar
Gill
Occasional Contributor
8 days ago

How to capture specific text from screen and than display it via log message.

Hi I am trying to capture on screen CartID and just need to display the cart number not the text saying SAP Cart ID: 

I tried using set variable value and creating a variable under the project  and than used the code expression to get the value 

and used log message to display the variable value but nothing is displaying when I run the keyword test. 

can anyone please share any video or steps they use to get that and to display exact value rather than just displaying the whole thing. I really appreciate it.

or if there is a video anyone have it'll be so much helpful. 

 

  • Gill's avatar
    Gill
    Occasional Contributor

    Thank you  I was able to figure it out. really appreciate. 

  • Hassan_Ballan's avatar
    Hassan_Ballan
    Regular Contributor

    When you use the Object Spy does it recognize the ID value independently, or it only recognize the entire panel?

    If it does not single out the ID, you will need to parse the content to extract the required value as rraghvani stated. 

    In any case, you will need to read a specific property value from your Mapped object Aliases.browser.pageUserDasboard.panelSapCardId, for example the value of contentText. 

    You can try the following example using https://www.w3schools.com/TAGs/tryit.asp?filename=tryhtml5_output 

    And you can log it directly or store into variable and then log the value

    Let me know if you need additional assistance.

  • rraghvani's avatar
    rraghvani
    Icon for Champion Level 3 rankChampion Level 3

    If the Object Spy tool shows the text value as "SAP CART ID: 12069799", then you can you use Regular Expression to extract the number. For example,

    function extractNumber() {
        var text = "SAP CART ID: 12069799";
        var match = text.match(/\d+/);
        Log.Message(match[0]);
    }