@@ -8,6 +8,30 @@ namespace Wndrr.Selenium
88{
99 public static class SeleniumUtils
1010 {
11+
12+ /// <summary>
13+ /// Changes the currently focused tab
14+ /// </summary>
15+ /// <param name="driver"></param>
16+ /// <param name="index">Target tab</param>
17+ /// <returns>
18+ /// false - when the requested index was outside of the possible range
19+ /// true - the tab was found, all clear
20+ /// </returns>
21+ public static bool SwitchToTab ( this IWebDriver driver , int index )
22+ {
23+ var switchAction = driver . SwitchTo ( ) ;
24+ // If the index is out of range
25+ if ( driver . WindowHandles . Count <= index )
26+ return false ;
27+
28+ var handle = driver . WindowHandles [ index ] ;
29+ switchAction . Window ( handle ) ;
30+
31+ return true ;
32+ }
33+
34+ #region SCROLL
1135 /// <summary>
1236 /// Vertically scrolls an element to the middle of the screen using JavaScript
1337 /// </summary>
@@ -35,28 +59,12 @@ public static void ScrollTo(this IWebDriver driver, IWebElement element)
3559 VerticalScrollTo ( driver , element ) ;
3660 }
3761
38- /// <summary>
39- /// Changes the currently focused tab
40- /// </summary>
41- /// <param name="driver"></param>
42- /// <param name="index">Target tab</param>
43- /// <returns>
44- /// false - when the requested index was outside of the possible range
45- /// true - the tab was found, all clear
46- /// </returns>
47- public static bool SwitchToTab ( this IWebDriver driver , int index )
48- {
49- var switchAction = driver . SwitchTo ( ) ;
50- // If the index is out of range
51- if ( driver . WindowHandles . Count <= index )
52- return false ;
62+ #endregion
5363
54- var handle = driver . WindowHandles [ index ] ;
55- switchAction . Window ( handle ) ;
56-
57- return true ;
58- }
64+ #region WAIT
5965
66+ #region URL CHANGE
67+
6068 /// <summary>
6169 /// Polls the driver URL until it changes or until the timeout expires
6270 /// <exception cref="TimeoutException"></exception>
@@ -96,6 +104,10 @@ public static void WaitUntilCurrentUrlChange(this IWebDriver driver, int timeout
96104 WaitUntilCurrentUrlChange ( driver , timeoutSpan , pollInterval ) ;
97105 }
98106
107+ #endregion
108+
109+ #region URL IS
110+
99111 /// <summary>
100112 /// Polls the driver URL until it changes to the targetUrl or until the timeout expires
101113 /// <exception cref="TimeoutException"></exception>
@@ -112,7 +124,7 @@ public static void WaitUntilUrlIs(this IWebDriver driver, string targetUrl, Time
112124 while ( true )
113125 {
114126 if ( driver . Url == targetUrl )
115- return ;
127+ return ;
116128
117129 var isTimeout = TimeSpan . Compare ( timer . Elapsed , timeout ) > 0 ;
118130 if ( isTimeout )
@@ -136,5 +148,9 @@ public static void WaitUntilUrlIs(this IWebDriver driver, string targetUrl, int
136148 var timeoutSpan = new TimeSpan ( 0 , 0 , 0 , 0 , timeout ) ;
137149 WaitUntilUrlIs ( driver , targetUrl , timeoutSpan , pollInterval ) ;
138150 }
151+
152+ #endregion
153+
154+ #endregion
139155 }
140156}
0 commit comments