1
0
Эх сурвалжийг харах

Work-around cases where JS based polyfills fail in exciting ways

Note in documentation limitations of this on some browsers.
George S. Baugh 8 жил өмнө
parent
commit
f5e9696c6e

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

@@ -1854,6 +1854,7 @@ sub execute_async_script {
             {
                 if ($self->{is_wd3}) {
                     $args[$i] = { 'element-6066-11e4-a52e-4f735466cecf' => ( $args[$i] )->{id} };
+                    $args[$i]->{ELEMENT} = $args[$i]->{id} if $self->browser_name eq 'chrome'; #XXX sometimes they prefer the latter/prior
                 } else {
                     $args[$i] = { 'ELEMENT' => ( $args[$i] )->{id} };
                 }
@@ -1924,6 +1925,7 @@ sub execute_script {
             {
                 if ($self->{is_wd3}) {
                     $args[$i] = { 'element-6066-11e4-a52e-4f735466cecf' => ( $args[$i] )->{id} };
+                    $args[$i]->{ELEMENT} = $args[$i]->{id} if $self->browser_name eq 'chrome'; #XXX sometimes they prefer the latter/prior
                 } else {
                     $args[$i] = { 'ELEMENT' => ( $args[$i] )->{id} };
                 }

+ 16 - 6
lib/Selenium/Remote/WebElement.pm

@@ -133,6 +133,10 @@ sub click {
     Submit a FORM element. The submit command may also be applied to any element
     that is a descendant of a FORM element.
 
+ Compatibility:
+    On webdriver3 enabled servers, this uses a JS shim, which may not submit correctly depending on the element you are attempting to submit.
+    Try clicking it if possible instead.
+
  Usage:
     $elem->submit();
 
@@ -140,7 +144,7 @@ sub click {
 
 sub submit {
     my ($self) = @_;
-    return $self->driver->execute_script("return arguments[0].submit();", {'element-6066-11e4-a52e-4f735466cecf'=> $self->{id}} ) if $self->driver->{is_wd3} && !(grep { $self->driver->browser_name eq $_ } qw{chrome MicrosoftEdge});
+    return $self->driver->execute_script("if (typeof arguments[0].submit === 'function') { return arguments[0].submit(); }; return 0;", {'element-6066-11e4-a52e-4f735466cecf'=> $self->{id}} ) if $self->driver->{is_wd3} && !(grep { $self->driver->browser_name eq $_ } qw{chrome MicrosoftEdge});
     my $res = { 'command' => 'submitElement', 'id' => $self->id };
     return $self->_execute_command($res);
 }
@@ -367,7 +371,9 @@ sub get_element_rect {
     determine an element's location for correctly generating native events.
 
  Compatibility:
-    Not available on WebDriver3 enabled selenium servers.
+    On Webdriver3 servers, we have to implement this with a JS shim.
+    This means in some contexts, you won't get any position returned, as the element isn't considered an element internally.
+    You may have to go up the element stack to find the element that actually has the bounding box.
 
  Output:
     {x:number, y:number} The X and Y coordinates for the element on the page.
@@ -379,11 +385,15 @@ sub get_element_rect {
 
 sub get_element_location_in_view {
     my ($self) = @_;
+    #XXX chrome is dopey here
     return $self->driver->execute_script(qq{
-        arguments[0].scrollIntoView();
-        var pos = arguments[0].getBoundingClientRect();
-        return {y:pos.top,x:pos.left};
-    }, {'element-6066-11e4-a52e-4f735466cecf'=> $self->{id}} ) if $self->driver->{is_wd3} && grep { $self->driver->browser_name eq $_ } ('firefox','internet explorer');
+        if (typeof(arguments[0]) !== 'undefined' && arguments[0].nodeType === Node.ELEMENT_NODE) {
+            arguments[0].scrollIntoView();
+            var pos = arguments[0].getBoundingClientRect();
+            return {y:pos.top,x:pos.left};
+        }
+        return {};
+    }, {'element-6066-11e4-a52e-4f735466cecf'=> $self->{id}} ) if $self->driver->{is_wd3} && grep { $self->driver->browser_name eq $_ } ('firefox','internet explorer', 'chrome');
     my $res = { 'command' => 'getElementLocationInView', 'id' => $self->id };
     return $self->_execute_command($res);
 }