Home » Test studio » when you can’t identify element on webpage and if it is returning 0 elements test studio c#

when you can’t identify element on webpage and if it is returning 0 elements test studio c#

There are possibilities that DOM gets changed or some elements inside DOM gets changed or get loaded dynamically after doing some operation on the webpage like selecting an item from a dropdown. So it is diffucult to identify the webelement in such cases. One simple way to handle this is.
Ex: 
ReadOnlyCollection<Element> rows = ActiveBrowser.Find.AllByXPath("//table//tbody//tr");
Log.WriteLine(rows.Count.ToString());

O/P: 0;

Solution: make use of RefreshDomTree() as below:

ActiveBrowser.RefreshDomTree(); // This will refresh dom before executing next line of code.
ReadOnlyCollection<Element> rows = ActiveBrowser.Find.AllByXPath("//table//tbody//tr");
Log.WriteLine(rows.Count.ToString());

O/P: 2;

 

 

 


3 Comments

Leave a comment

Your email address will not be published. Required fields are marked *