Created
June 30, 2023 00:46
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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