This is a migrated thread and some comments may be shown as answers.

Trying to find, extract, and compare variable ids

4 Answers 32 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
April
Top achievements
Rank 1
April asked on 30 Oct 2018, 03:51 PM

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);
}

4 Answers, 1 is accepted

Sort by
0
April
Top achievements
Rank 1
answered on 30 Oct 2018, 04:11 PM

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

 

0
Accepted
Elena
Telerik team
answered on 01 Nov 2018, 04:56 PM
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!
0
April
Top achievements
Rank 1
answered on 06 Nov 2018, 02:50 PM
Looks like the culprit was your #2, so that's fixed, and now everything works! Thank you!
0
Elena
Telerik team
answered on 06 Nov 2018, 04:34 PM
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!
Tags
General Discussions
Asked by
April
Top achievements
Rank 1
Answers by
April
Top achievements
Rank 1
Elena
Telerik team
Share this question
or