Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save IJsWorkshop/9462094f4ee19c605513401f61fa4268 to your computer and use it in GitHub Desktop.
Save IJsWorkshop/9462094f4ee19c605513401f61fa4268 to your computer and use it in GitHub Desktop.
Using Selenium to access Gmail - Correction for ChromeDriver to fix wait feature and element is visible.
static void Delay(TimeSpan ts)
{
var stopwatch = Stopwatch.StartNew();
stopwatch.Start();
while (stopwatch.Elapsed.TotalSeconds <= ts.Seconds) { }
stopwatch.Stop();
}
public static bool IsVisible(this IWebDriver webDriver, By locator, TimeSpan timeOut)
{
bool isDisplayed = false;
var sw = Stopwatch.StartNew();
sw.Start();
while (!isDisplayed || sw.Elapsed.Seconds <= timeOut.Seconds)
{
IWebElement ele = null;
try
{
ele = webDriver.FindElement(locator);
}
catch (Exception)
{
//Debug.WriteLine($"timeout :{sw.Elapsed.Seconds} : {e.Message}");
}
if (ele != null && ele.Displayed)
{
isDisplayed = true;
sw.Stop();
return true;
}
Delay(TimeSpan.FromSeconds(1));
}
sw.Stop();
return false;
}
public static IWebDriver Wait(this IWebDriver webDriver, TimeSpan ts)
{
var stopwatch = Stopwatch.StartNew();
stopwatch.Start();
while (stopwatch.Elapsed.TotalSeconds <= ts.Seconds)
{
// Debug.WriteLine(stopwatch.Elapsed.TotalSeconds);
}
stopwatch.Stop();
return webDriver;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment