Extracting a partial element

2 posts, 0 answers
  1. Lynsey
    Lynsey avatar
    4 posts
    Member since:
    Jun 2011

    Posted 03 Nov 2011 Link to this post

    I have a test that uploads a document from my desktop and then the web application returns a message to say 'successfully uploaded document with ID of ABC123'.  I want to extract the document ID part of the message only, Is this possible?  I have tried to do this using the quick tasks but can only extract the whole message.
  2. Stoich
    Stoich avatar
    1 posts

    Posted 03 Nov 2011 Link to this post

    Hello Lynsey,
        the whole String:
    successfully uploaded document with ID of ABC123 is probably contained within a single HTML element (e.g. a paragraph <p>) and this is why you can only use the "Extract" feature to get the entire String.

    You can work around this limitation with a relatively simple coded solution.
    You can access and set Extracted values in code as seen here:

    You can use simple C#/VB logic in order to re-work the Extracted variable to only contain the ID. From there you can change the extracted variable value to the re-worked version. Here's an example of how to do this in code (let's say the string was extracted in a variable "idString"):
    String myId = this.GetExtractedValue("idString").ToString(); //Get whole extracted string
    int n = myId.IndexOf("ID of ")+6; //Get the index of the start of the actual ID.
    //The whole string is "successfully uploaded document with ID of ABC123" but we
    //we need the content after "ID of". We get the start index of this string and add 6 to it
    //because the string itself contains 6 characters
    myId = myId.Substring(n); //Remove the contet we don't need
    this.SetExtractedValue("idString",myId); //Set the new value to the extracted variable
    Log.WriteLine(this.GetExtractedValue("idString").ToString()); //Write the ID to the Log file

    Let me know how it goes.

    All the best,
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top