1- using Selenium . Core ;
1+ using System ;
2+ using Selenium . Core ;
23using System . ComponentModel ;
34using System . Runtime . InteropServices ;
45
56namespace Selenium {
67
78 /// <summary>
8- /// Timeouts object
9+ /// Timeouts used in in waiting
910 /// </summary>
1011 /// <example>
11- /// Sets the implicit timout to 1 second
12+ /// Sets the deault operational time out to 1 second:
1213 /// <code lang="vb">
1314 /// driver.Timeouts.ImplicitWait = 1000
1415 /// </code>
16+ /// Tells the driver process to set its element location timeout to 1 second:
17+ /// <code lang="vb">
18+ /// driver.Timeouts.Implicit = 1000
19+ /// </code>
1520 /// </example>
1621 [ ProgId ( "Selenium.Timeouts" ) ]
1722 [ Guid ( "0277FC34-FD1B-4616-BB19-44A424DB3F50" ) ]
1823 [ Description ( "Timeouts management" ) ]
1924 [ ComVisible ( true ) , ClassInterface ( ClassInterfaceType . None ) ]
2025 public class Timeouts : ComInterfaces . _Timeouts {
26+ private const String ENDPOINT = "/timeouts" ;
2127
22- private static void SendTimeoutScript ( RemoteSession session , int timeout ) {
23- session . Send ( RequestMethod . POST , "/timeouts" , "type" , "script" , "ms" , timeout ) ;
28+ internal static void SendTimeoutScript ( RemoteSession session , int timeout ) {
29+ session . Send ( RequestMethod . POST , ENDPOINT , "type" , "script" , "ms" , timeout ) ;
2430 }
2531
26- private static void SendTimeoutPageLoad ( RemoteSession session , int timeout ) {
27- session . Send ( RequestMethod . POST , "/timeouts" , "type" , "page load" , "ms" , timeout ) ;
32+ internal static void SendTimeoutPageLoad ( RemoteSession session , int timeout ) {
33+ session . Send ( RequestMethod . POST , ENDPOINT , "type" , "page load" , "ms" , timeout ) ;
2834 }
2935
30- private static void SendTimeoutImplicit ( RemoteSession session , int timeout ) {
31- session . Send ( RequestMethod . POST , "/timeouts" , "type" , "implicit" , "ms" , timeout ) ;
36+ internal static void SendTimeoutImplicit ( RemoteSession session , int timeout ) {
37+ session . Send ( RequestMethod . POST , ENDPOINT , "type" , "implicit" , "ms" , timeout ) ;
3238 }
3339
3440
@@ -42,6 +48,12 @@ private static void SendTimeoutImplicit(RemoteSession session, int timeout) {
4248 /// <summary>
4349 /// Amount of time that Selenium will wait for commands to complete. Default is 3000ms
4450 /// </summary>
51+ /// <remarks>
52+ /// This timeout is not linked to the driver process
53+ /// <see href="https://w3c.github.io/webdriver/#timeouts">implicit timeout</see>.
54+ /// It just a SeleniumBasic's default time for an element search operation would continue repeating a search requests
55+ /// until the timeout is reached.
56+ /// </remarks>
4557 /// <remarks>Default is 3000ms</remarks>
4658 public int ImplicitWait {
4759 get {
@@ -53,12 +65,37 @@ public int ImplicitWait {
5365 }
5466 }
5567
68+ /// <summary>
69+ /// Amount of time the driver process should wait to complete when locating an element.
70+ /// </summary>
71+ /// <remarks>
72+ /// Default is 0ms. See <see href="https://w3c.github.io/webdriver/#timeouts">implicit timeout</see>
73+ /// </remarks>
74+ public int Implicit {
75+ get {
76+ try {
77+ Dictionary dict = ( Dictionary ) _session . Send ( RequestMethod . GET , ENDPOINT ) ;
78+ if ( dict != null )
79+ return Convert . ToInt32 ( dict [ "implicit" ] ) ;
80+ } catch { }
81+ return - 1 ;
82+ }
83+ set {
84+ if ( _session != null )
85+ SendTimeoutImplicit ( _session , value ) ;
86+ }
87+ }
88+
5689 /// <summary>
5790 /// Amount of time the driver should wait while loading a page before throwing an exception.
5891 /// </summary>
5992 /// <remarks>Default is 60000ms</remarks>
6093 public int PageLoad {
6194 get {
95+ Dictionary dict = ( Dictionary ) _session . Send ( RequestMethod . GET , ENDPOINT ) ;
96+ if ( dict != null ) {
97+ timeout_pageload = Convert . ToInt32 ( dict [ "pageLoad" ] ) ;
98+ }
6299 return timeout_pageload ;
63100 }
64101 set {
@@ -75,6 +112,10 @@ public int PageLoad {
75112 /// <remarks>Default is 15000ms</remarks>
76113 public int Script {
77114 get {
115+ Dictionary dict = ( Dictionary ) _session . Send ( RequestMethod . GET , ENDPOINT ) ;
116+ if ( dict != null ) {
117+ timeout_script = Convert . ToInt32 ( dict [ "script" ] ) ;
118+ }
78119 return timeout_script ;
79120 }
80121 set {
@@ -102,7 +143,7 @@ public int Server {
102143 internal void SetSession ( RemoteSession session ) {
103144 _session = session ;
104145 SendTimeoutPageLoad ( _session , timeout_pageload ) ;
105- SendTimeoutScript ( _session , timeout_pageload ) ;
146+ SendTimeoutScript ( _session , timeout_script ) ;
106147 }
107148
108149 }
0 commit comments