Bläddra i källkod

Add get_element_location_in_view shim

George S. Baugh 8 år sedan
förälder
incheckning
b4f04cd05c
2 ändrade filer med 6 tillägg och 1 borttagningar
  1. 1 1
      at/sanity.test
  2. 5 0
      lib/Selenium/Remote/WebElement.pm

+ 1 - 1
at/sanity.test

@@ -190,7 +190,7 @@ is( $l2->is_enabled(),0,"is_enabled works (WD3)");
 ok( $l2->get_element_location()->{x},"Can get element rect (WD3)");
 ok( $l2->get_size()->{'height'}, "Size shim on rect works (WD3)");
 is( $l2->get_tag_name(),'input',"get_tag_name works (WD3)");
-isnt( exception { $l2->get_element_location_in_view() }, undef, "get_element_location_in_view not available in WD3");
+ok( defined $l2->get_element_location_in_view()->{x}, "get_element_location_in_view polyfill works (WD3)");
 
 is($driver->find_element('hidon','id')->is_displayed(),0,"is_displayed returns false for type=hidden elements");
 is($driver->find_element('no-see-em','id')->is_displayed(),0,"is_displayed returns false for display=none");

+ 5 - 0
lib/Selenium/Remote/WebElement.pm

@@ -376,6 +376,11 @@ sub get_element_rect {
 
 sub get_element_location_in_view {
     my ($self) = @_;
+    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');
     my $res = { 'command' => 'getElementLocationInView', 'id' => $self->id };
     return $self->_execute_command($res);
 }