Trying to find, extract, and compare variable ids

5 posts, 1 answers
  1. April
    April avatar
    10 posts
    Member since:
    Oct 2016

    Posted 30 Oct 2018 Link to this post

    As the title says, I've been trying to sift through a DOM that has a bunch of "inbox" messages that are all lined up in a div. I've been trying just to grab the first inbox message's div and get it's id value and set it as an extracted value. Once I click on the message, and and come back to the page, it no longer is marked as "unread" and I want to grab that same id again to compare. (these messages are sorted by most recent, so it will always be the first message.)

    You can see in the code block below that the unread messages are marked with a specific class, which lets me grab the first message. I also tried grabbing it as an element type (not using the <HtmlDiv>), and getting the ID via that way, it also didn't work.

    Since these messages all have unique, generated ids based on their content, I haven't been able to work out a way to extract and compare them. Let me know if you need anything else from me, and I appreciate the help.

    [CodedStep(@"Extract id of first new inbox message")]
    public void extractFirstNewInboxMessage()
    {
        HtmlDiv firstMessageElement = ActiveBrowser.Find.ByAttributes<HtmlDiv>("class= row message unread");
        string id = firstMessageElement.ID;
        SetExtractedValue("firstNewMessageElementID", id);
    }
     
    [CodedStep(@"Extract id of first inbox message")]
    public void extractFirstOldInboxMessage()
    {
        HtmlDiv firstMessageElement = ActiveBrowser.Find.ByAttributes<HtmlDiv>("class= row message");
        SetExtractedValue("firstOldMessageElementID", firstMessageElement.ID);
    }
     
    [CodedStep(@"compare extracted inbox messages")]
    public void compareInboxMessage()
    {
        string newMessage = GetExtractedValue("firstNewMessageElementID").ToString();
        string oldMessage = GetExtractedValue("firstOldMessageElementID").ToString;
         
        //bool value
        bool a = false;
         
        if (newMessage == oldMessage)
        {
            a = true;
        }
        Assert.IsTrue(a);
    }
  2. April
    April avatar
    10 posts
    Member since:
    Oct 2016

    Posted 30 Oct 2018 in reply to April Link to this post

    I included a small snapshot of the dom. I should also mention that it fails on the first function. 

     

  3. Answer
    Elena
    Admin
    Elena avatar
    1104 posts

    Posted 01 Nov 2018 Link to this post

    Hi April,

    Thank you for sharing the code snippet. 

    Since the code is failing on the first function, probably there is anything wrong and you need to debug and fix it. You didn't mention if there is an error or failure details, so please note my below recommendations are only assumptions.

    1. Please include Assertions for each element while debugging the code. That way you will know which is the not found element or which is the last successful line of code executed. In this example the first assertion to add is right after the Find() to locate the div. 

    Assert.IsNotNull(firstMessageElement);

    2. The class from the DOM tree does not match the one listed in the code. There is a space after the equal sign and should be as follows: 

    "class=row message unread"

    3. The oldMessage variable assignment has missing brackets.

    4. You might need to include RefreshDomTree method before some actions on the page. 

    Please apply the above and verify if the code works this time. If not, I will appreciate if you send me any execution or error log which can expose further details what is failing. 

    Thank you in advance. 

    Regards,
    Elena Tsvetkova
    Progress Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  4. April
    April avatar
    10 posts
    Member since:
    Oct 2016

    Posted 06 Nov 2018 in reply to Elena Link to this post

    Looks like the culprit was your #2, so that's fixed, and now everything works! Thank you!
  5. Elena
    Admin
    Elena avatar
    1104 posts

    Posted 06 Nov 2018 Link to this post

    Hello April,

    Thanks for getting back to me. Glad to hear we managed to identify and fix the issue. 

    Regards,
    Elena Tsvetkova
    Progress Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
Back to Top