Imagine a scenario where an action is triggered by clicking a button on a webpage. Let's say this action takes X seconds to complete, and during this time a div
appears in the center of the page. Once the action is done, the div
disappears, and focus shifts to element E.
1) In my Selenium test (using C#):
stopwatch.Restart();
button.Click();
while (driver.FindElementsById(PopupDivId).Count != 0)
{
Thread.Sleep(10);
}
stopwatch.Stop();
2) And in a JavaScript test on the webpage:
Button click handler:
console.time('test');
Element E gets focus:
console.log(document.getElementById('My_PopupDivId')); // just to confirm it returns null
console.timeEnd('test');
It seems that the measurements from Selenium are approximately double those from direct JavaScript measurements. (400ms vs 800ms).
Is there an issue with my code causing this discrepancy, or is it simply due to Selenium's lack of precision? (Is it even practical to use Selenium for measuring JavaScript/DOM performance?)