Browse Source

added close method, modified documentation

Gordon Child 14 years ago
parent
commit
f4d8f14ccc
1 changed files with 37 additions and 3 deletions
  1. 37 3
      lib/Selenium/Remote/Driver.pm

+ 37 - 3
lib/Selenium/Remote/Driver.pm

@@ -389,6 +389,28 @@ sub set_implicit_wait_timeout {
     return $self->_execute_command($res, $params);
     return $self->_execute_command($res, $params);
 }
 }
 
 
+=head2 close
+
+ Description:
+    Close the current window.
+
+ Usage:
+    $driver->close();
+ or
+    #close a popup window
+    my $handles = $driver->get_window_handles;
+    $driver->switch_to_window($handles->[1]);
+    $driver->close();
+    $driver->switch_to_window($handles->[0]);
+
+=cut
+
+sub close {
+  my $self = shift;
+  my $res = { 'command' => 'close' };
+  $self->_execute_command($res);
+}
+
 =head2 quit
 =head2 quit
 
 
  Description:
  Description:
@@ -425,7 +447,7 @@ sub get_current_window_handle {
     return $self->_execute_command($res);
     return $self->_execute_command($res);
 }
 }
 
 
-=head2 get_current_window_handles
+=head2 get_window_handles
 
 
  Description:
  Description:
     Retrieve the list of window handles used in the session.
     Retrieve the list of window handles used in the session.
@@ -434,7 +456,13 @@ sub get_current_window_handle {
     ARRAY of STRING - list of the window handles
     ARRAY of STRING - list of the window handles
 
 
  Usage:
  Usage:
-    print Dumper($driver->get_current_window_handles());
+    print Dumper $driver->get_window_handles;
+ or
+    # get popup, close, then back
+    my $handles = $driver->get_window_handles;
+    $driver->switch_to_window($handles->[1]);
+    $driver->close;
+    $driver->switch_to_window($handles->[0]);
 
 
 =cut
 =cut
 
 
@@ -753,7 +781,7 @@ sub available_engines {
  Description:
  Description:
     Change focus to another frame on the page. If the frame ID is null, the
     Change focus to another frame on the page. If the frame ID is null, the
     server will switch to the page's default content.
     server will switch to the page's default content.
-    
+
  Input: 1
  Input: 1
     Required:
     Required:
         {STRING | NUMBER | NULL} - ID of the frame which can be one of the three
         {STRING | NUMBER | NULL} - ID of the frame which can be one of the three
@@ -787,6 +815,12 @@ sub switch_to_frame {
 
 
  Usage:
  Usage:
     $driver->switch_to_window('MY Homepage');
     $driver->switch_to_window('MY Homepage');
+ or
+    # close a popup window and switch back
+    my $handles = $driver->get_window_handles;
+    $driver->switch_to_window($handles->[1]);
+    $driver->close;
+    $driver->switch_to_window($handles->[0]);
 
 
 =cut
 =cut