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

Issues with finding elements with dynamic content

2 Answers 66 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Julian
Top achievements
Rank 1
Julian asked on 02 Sep 2014, 11:34 AM
Hello,

we are currently evaluating Telerik Test Studio and so far are pleased with the product. We do have, however, an issue regarding finding elements which have dynamic content, that is dynamic InnerText respectively TextContent. The workflow in our scenario is the following:

1. I log into our application
2. I create a new object and assign it a static name
3. I save said object
4. I use a search bar, entering the previously assigned name
5. The corresponding object is displayed
6. I click it and in the following dialog delete it

After having recorded this test, I modified steps 2, 4 and 6 so that they work with dynamic names. For steps 2 and 4 I added an extraction step so that I can use the extracted value for name assignment and searching. For step 6 I first took a look at the Find Expression of the recorded element, which was "tagname=span, TextContent exactly XYZ", where XYZ was the name I statically assigned. I then converted this step into a coded step, using the following statements:

1.Dim objectName As Object = GetExtractedValue("objectNameVariable") 'The variable used in the extraction step
2.Dim objectSpan As HtmlSpan = Find.ByExpression(Of HtmlSpan)("tagname=span", "TextContent=" + objectName.ToString())
3.objectSpan.Click(false)

While I believe that this code snippet should do exactly what the original Find Expression did (except that it works for dynamic names), it did not work reliably. Most of the time after step 5 (this step passed without problems) the desired HtmlSpan could not be found. Only when I went into debug mode and passed through the test steps very slowly, it succeeded sometimes. After having searched on your forums for a while I stumbled upon someone claiming that Test Studio sometimes clicks on wrong elements. There, a solution was found by adding the ActiveBrowser.RefreshDomTree()
System.Threading.Thread.Sleep(5000) method right before doing the click action. I did the same for my coded step, also adding a 5-second wait after refreshing the DOM (by using System.Threading.Thread.Sleep(5000)). With this code, the test ran successfully about half the time, maybe a little bit more. I added another call of RefreshDomTree() and another 5-second wait, and now it seems that everything is working fine. My code now looks like this:

1.'The span is located here
2.ActiveBrowser.RefreshDomTree()
3.System.Threading.Thread.Sleep(5000)
4.ActiveBrowser.RefreshDomTree()
5.System.Threading.Thread.Sleep(5000)
6.'The click action is here
  
I understand that problems like an outdated DOM tree can occur and I would be happy if the problem could be solved by adding one call of ActiveBrowser.RefreshDomTree(). However, having to add two calls of it including the following waits looks more like a workaround than a solution to me. Is there any other possibility to solve this issue? Unfortunately, I cannot provide any project files as our application is still under development and shall not be seen by third parties.

Regards
Julian

2 Answers, 1 is accepted

Sort by
0
Julian
Top achievements
Rank 1
answered on 05 Sep 2014, 08:32 AM
Just wanted to add this here: it seems that one call to RefreshDomTree() is sufficient, though there needs to be some waiting time before and after, like Miguel wrote (I think he removed his post, I can't see it anymore). I am currently working with:

1.System.Threading.Thread.Sleep(2000)
2.ActiveBrowser.RefreshDomTree()
3.System.Threading.Thread.Sleep(2000)

My tests are running fine with that. It might be possible to reduce the waiting time even more, I didn't try that out, though. I am okay with 4 seconds, compared with the ten second wait before.

Regards
Julian
0
Boyan Boev
Telerik team
answered on 05 Sep 2014, 11:50 AM
Hi Julian,

Thank you for contacting us.

Without seeing the application and its behavior I cannot say why is this happening.

You can try also with one sleep before the refresh.

Hope this helps.

Regards,
Boyan Boev
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Julian
Top achievements
Rank 1
Answers by
Julian
Top achievements
Rank 1
Boyan Boev
Telerik team
Share this question
or