File tree Expand file tree Collapse file tree 3 files changed +71
-5
lines changed
lib/capybara/cuprite/javascripts Expand file tree Collapse file tree 3 files changed +71
-5
lines changed Original file line number Diff line number Diff line change @@ -84,7 +84,6 @@ class Cuprite {
84
84
return true ;
85
85
}
86
86
87
-
88
87
isDisabled ( node ) {
89
88
let xpath = "parent::optgroup[@disabled] | \
90
89
ancestor::select[@disabled] | \
@@ -344,10 +343,24 @@ class Cuprite {
344
343
345
344
_isInViewport ( node ) {
346
345
let rect = node . getBoundingClientRect ( ) ;
347
- return rect . top >= 0 &&
348
- rect . left >= 0 &&
349
- rect . bottom <= window . innerHeight &&
350
- rect . right <= window . innerWidth ;
346
+
347
+ let inViewport = rect . top >= 0 &&
348
+ rect . left >= 0 &&
349
+ rect . bottom <= window . innerHeight &&
350
+ rect . right <= window . innerWidth ;
351
+
352
+ if ( inViewport ) {
353
+ // check if obscured by another element
354
+ let x = rect . width / 2 ;
355
+ let y = rect . height / 2 ;
356
+
357
+ let px = rect . left + x ,
358
+ py = rect . top + y ,
359
+ e = document . elementFromPoint ( px , py ) ;
360
+ return node == e ;
361
+ }
362
+
363
+ return false ;
351
364
}
352
365
353
366
select ( node , value ) {
Original file line number Diff line number Diff line change @@ -514,6 +514,12 @@ def create_screenshot(file, *args)
514
514
expect ( @driver . body ) . to include ( "x: 100, y: 150" )
515
515
end
516
516
517
+ it "supports clicking overlayed elements" do
518
+ @session . visit ( "/cuprite/click_overlay" )
519
+ @session . click_link "hidden link"
520
+ expect ( @driver . body ) . to include ( "hidden-link" )
521
+ end
522
+
517
523
it "supports executing multiple lines of javascript" do
518
524
@driver . execute_script <<-JS
519
525
var a = 1
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head >
4
+ < style type ="text/css ">
5
+ body {
6
+ width : 800px ;
7
+ margin : 0 ;
8
+ }
9
+ # hidden-link {
10
+ position : relative;
11
+ top : 740px ;
12
+ }
13
+ # wrapper {
14
+ height : 1200px ;
15
+ }
16
+ # footer {
17
+ position : fixed;
18
+ left : 0 ;
19
+ bottom : 0 ;
20
+ width : 100% ;
21
+ background-color : red;
22
+ color : white;
23
+ text-align : center;
24
+ height : 100px ;
25
+ }
26
+ </ style >
27
+ < script type ="text/javascript ">
28
+ window . onload = function ( ) {
29
+ var log = document . querySelector ( "#log" )
30
+ var boxes = document . querySelectorAll ( "#hidden-link" )
31
+ for ( var i = 0 ; i < boxes . length ; i ++ ) {
32
+ var el = boxes [ i ]
33
+ el . onclick = function ( ) {
34
+ log . textContent = this . id
35
+ }
36
+ }
37
+ }
38
+ </ script >
39
+ </ head >
40
+ < body >
41
+ < div id ="log "> </ div >
42
+ < div id ="wrapper ">
43
+ < a id ="hidden-link " href ="# "> hidden link</ a >
44
+ </ div >
45
+ < div id ="footer "> </ div >
46
+ </ body >
47
+ </ html >
You can’t perform that action at this time.
0 commit comments