Skip to content

Instantly share code, notes, and snippets.

@elgatov
Created May 28, 2019 20:21
Show Gist options
  • Save elgatov/2d4acc4a9399d8e7fc194ab2ecd4bce8 to your computer and use it in GitHub Desktop.
Save elgatov/2d4acc4a9399d8e7fc194ab2ecd4bce8 to your computer and use it in GitHub Desktop.
public static bool RetryingClick(this IWebElement element)
{
bool clicked = false;
Stopwatch crono = Stopwatch.StartNew();
while (crono.Elapsed < TimeSpan.FromSeconds(10) && !clicked )
{
try
{
if (element != null && element.Displayed && element.Enabled)
{
element.Click();
clicked = true;
}
}
catch (WebDriverException)
{ }
Thread.Sleep(250);
}
if (clicked)
return true;
else
throw new WebDriverTimeoutException("El elemento no ha sido clicado en el tiempo límite. Finalizando ejecución");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment