-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWaitHelpers.cs
73 lines (67 loc) · 1.86 KB
/
WaitHelpers.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using OpenQA.Selenium;
using System.Collections.ObjectModel;
// Waiting methods
public static class WaitH
{
// Method for waiting until the item is available for clicking
public static IWebElement WaitUntilElementClickable(IWebDriver driver, By by)
{
IWebElement element = null;
while (true) // Infinite loop until we return an element
{
try
{
element = driver.FindElement(by);
if (element.Displayed && element.Enabled)
{
return element;
}
}
catch (NoSuchElementException)
{
// Element not found, continue the loop
}
}
}
// Method to wait until the list of items is visible
public static ReadOnlyCollection<IWebElement> WaitUntilElementsVisible(IWebDriver driver, By by)
{
ReadOnlyCollection<IWebElement> elements = null;
while (true)
{
try
{
elements = driver.FindElements(by);
if (elements != null && elements.Count > 0)
{
return elements;
}
}
catch (NoSuchElementException)
{
}
}
}
// Method for waiting for element visibility
public static IWebElement WaitUntilElementVisible(IWebDriver driver, By by)
{
IWebElement element = null;
while (true)
{
try
{
element = driver.FindElement(by);
if (element.Displayed)
{
return element;
}
}
catch (NoSuchElementException)
{
}
catch (ElementNotVisibleException)
{
}
}
}
}