I have an IWebElement (a div) that contains a child element half of the time. I want to see if it contains the child element and if so, I want to capture it. I do something like this:
IWebElement firstChild;
try
{
firstChild = divElement.FindElement(By.XPath("*"));
}
catch (NoSuchElementException e)
{
// catch and handling...
}
But this is slow on three parts:
1. The use of By.XPath("*")
2. FindElement that is slow in case an element does not exist
3. try/catch is a slower mechanism, I'd rather want a returned boolean on an existing of an item
How can I speed up this way of detecting child elements?
EDIT:
To clarify: The test I am performing runs on grids with divs, a typical grid is 4 x 16, so 64 fields. I want to transform this grid into a DataTable
to compare it to the expected outcome. The capturing of these fields to the datatable runs in 22 seconds in total. It is not performing very bad, but I'd like to shave off those precious seconds.
UPDATE:
I managed to do it by capturing the grid with the HTML Agility Pack. Unfortunately (there is always something), the values for the input
elements could not be captured because they are dynamically set. As a solution I'd let the HAP return the Ids of the input elements and capture the values with FindElement(By.Id(inputId))
which is blazingly fast compared to other Selenium selection methods.
To keep a long story short: I managed to reduce the capture time from around 22 seconds to less than 3 seconds, a more than 600% performance improvement.