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

Can not mouseover object

1 Answer 75 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ha
Top achievements
Rank 1
Ha asked on 12 Jul 2012, 06:24 AM
Hi
I customized code for step delete language ọbject.
But it is not successfully. Only delete object 1,3,5,7
Could you help me?
*******************************
 public void DeleteAllLanguages_CodedStep1()
        {
               
            ActiveBrowser.RefreshDomTree();            
            
            HtmlDiv htmlDiv = Find.ById<HtmlDiv>("dnn_ctr438_EditRegionLanguage_UP");  
            List<HtmlListItem> listItemsCollection = htmlDiv.Find.AllByAttributes<HtmlListItem>("class=inline").ToList();
            System.Threading.Thread.Sleep(1000);
            Log.WriteLine("Number of language object:"+listItemsCollection.Count);
            System.Threading.Thread.Sleep(1000);
            foreach(HtmlListItem listItem in listItemsCollection)
            {
                Log.WriteLine("1111111111111Item");
                listItem.MouseHover();
                System.Threading.Thread.Sleep(1000);
                Log.WriteLine(string.Format("BBBBBBBBBBBMouseover"));
                
                IList<HtmlControl> delete_div = listItem.Find.AllByAttributes<HtmlControl>("class=body-component-menu-delete");
                if((delete_div != null) && (delete_div.Count > 0))
                    {
                        Log.WriteLine(string.Format("language tile object deleted"));
                        delete_div[0].MouseClick();
                        System.Threading.Thread.Sleep(1000);
                        
                    }
            }
        }
Please refer to attachment

Thanks

1 Answer, 1 is accepted

Sort by
0
Stoich
Telerik team
answered on 17 Jul 2012, 09:19 AM
Hello,
the problem is that you're editing the HTML code of the page. This then affects how your code runs.

You use the collection listItemsCollection to go through each element in the page. And as you access each element - you delete it. This changes the content of the collection - the collection continuously checks what's going on in the page.

Here's what's happening:
at the start of the foreach loop all the elements are stored in the collection like so (zero-based indexing):
0 --> someValue
1 --> differentValue
2 --> thirdValue
3 -->fourthValue
etc.

When you go into the first cycle of the loop and you delete someValue - the collection gets rearranged like so:
0 --> different value
1 --> thirdValue
2 --> fourthValue
etc.

Now when your foreach loop goes into cycle 1 - it accesses thirdValue. It misses differentValue. That's why your test is deleting only half of the entries.

So how do you overcome this deficiency? The easiest way is to go through the list in reverse order… delete the last item first and work back to index 0.

Regards,
Stoich
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Ha
Top achievements
Rank 1
Answers by
Stoich
Telerik team
Share this question
or