Bladeren bron

Implemented /session/:sessionId/keys resource as send_keys_to_active_element in Driver module.

Aditya Ivaturi 14 jaren geleden
bovenliggende
commit
af73bcec2b
2 gewijzigde bestanden met toevoegingen van 41 en 0 verwijderingen
  1. 4 0
      lib/Selenium/Remote/Commands.pm
  2. 37 0
      lib/Selenium/Remote/Driver.pm

+ 4 - 0
lib/Selenium/Remote/Commands.pm

@@ -164,6 +164,10 @@ sub new {
                'method' => 'POST',
                'url' => "session/:sessionId/element/:id/value"
         },
+        'sendKeysToActiveElement' => {
+               'method' => 'POST',
+               'url' => "session/:sessionId/keys"
+        },
         'sendModifier' => {
                'method' => 'POST',
                'url' => "session/:sessionId/modifier"

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

@@ -286,12 +286,49 @@ sub status {
     my $string = $driver->get_alert_text;
 
 =cut
+
 sub get_alert_text {
   my ($self) = @_;
   my $res = { 'command' => 'getAlertText' };
   return $self->_execute_command($res);
 }
 
+=head2 send_keys_to_active_element
+
+ Description:
+    Send a sequence of key strokes to the active element. This command is
+    similar to the send keys command in every aspect except the implicit
+    termination: The modifiers are not released at the end of the call.
+    Rather, the state of the modifier keys is kept between calls, so mouse
+    interactions can be performed while modifier keys are depressed.
+
+ Input: 1
+    Required:
+        {ARRAY | STRING} - Array of strings or a string.
+
+ Usage:
+    $driver->send_keys_to_active_element('abcd', 'efg');
+    $driver->send_keys_to_active_element('hijk');
+    
+    or
+    
+    # include the WDKeys module
+    use Selenium::Remote::WDKeys;
+    .
+    .
+    $driver->send_keys_to_active_element(KEYS->{'space'}, KEYS->{'enter'});
+
+=cut
+
+sub send_keys_to_active_element {
+    my ($self, @strings) = @_;
+    my $res = { 'command' => 'sendKeysToActiveElement' };
+    my $params = {
+        'value' => \@strings,
+    };
+    return $self->_execute_command($res, $params);
+}
+
 =head2 send_keys_to_alert
 
 Synonymous with send_keys_to_prompt