I think you may want to look into WebDriverWait class in selenium. I mostly work with selenium in C# so hopefully this code is correct in VB.net (i didn't test it).
First i'll start with the C# example
var wait = new WebDriverWait(driver, new TimeSpan(0, 0, 45));
wait.IgnoreExceptionTypes(typeof(StaleElementReferenceException));
wait.Until(webDriver =>
{
return webDriver.FindElements(By.Id("someDynamicElement")).Where(m => m.Displayed).Any();
});
So the idea is that
wait.Until
will continue to loop until a condition is met that is true (the xml doc on this method is stupid, it says "until a condition is neither null nor false"...so until its true).
Also, you give it a max timeout of 45 seconds so if it finds what it needs in 2 seconds, great, if it takes 10 seconds then thats fine too...you don't have to require selenium to wait X number of seconds unnecessarily is the idea.
So converting it to vb.net i think would be something like this.
Dim wait As New WebDriverWait(webDriver, TimeSpan.FromSeconds(seconds))
wait.Until(Function(webDriver)
Return webDriver.FindElement(By.Id("someDynamicElement")).Enabled And webDriver.FindElement(By.Id("someDynamicElement")).Displayed
End Function)
The only downside to this is that on every page load you'll need to use the above sample for at least the first element so that way you don't have to resort to a
Thread.Sleep
or something like that.