瀏覽代碼

switch_to_frame can now accept WebElement as an input.

Aditya Ivaturi 13 年之前
父節點
當前提交
e31b889078
共有 1 個文件被更改,包括 12 次插入3 次删除
  1. 12 3
      lib/Selenium/Remote/Driver.pm

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

@@ -1049,25 +1049,34 @@ sub available_engines {
 
  Description:
     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. You can also switch to a
+    WebElement, for e.g. you can find an iframe using find_element & then
+    provide that as an input to this method. Also see e.g. 
 
  Input: 1
     Required:
-        {STRING | NUMBER | NULL} - ID of the frame which can be one of the three
+        {STRING | NUMBER | NULL | WebElement} - ID of the frame which can be one of the three
                                    mentioned.
 
  Usage:
     $driver->switch_to_frame('frame_1');
+    or
+    $driver->switch_to_frame($driver->find_element('iframe', 'tag_name'));
 
 =cut
 
 sub switch_to_frame {
     my ( $self, $id ) = @_;
     my $json_null = JSON::null;
+    my $params;
     $id = ( defined $id ) ? $id : $json_null;
 
     my $res    = { 'command' => 'switchToFrame' };
-    my $params = { 'id'      => $id };
+    if (ref $id eq 'Selenium::Remote::WebElement') {
+        $params = { 'id' => {'ELEMENT' => $id->{'id'}}};
+    } else {
+        $params = { 'id'      => $id };
+    }
     return $self->_execute_command( $res, $params );
 }