Skip to content

Commit 9117634

Browse files
author
Dmitriy Robota
committed
Add scroll element into view
1 parent 042f87a commit 9117634

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
*** Settings ***
2+
Documentation Tests Scroll Into View Verification
3+
Suite Setup Open Browser To Start Page
4+
Resource ../resource.robot
5+
6+
*** Variables ***
7+
${TEXT}= You scrolled in div.
8+
9+
*** Test Cases ***
10+
Verify Scroll Element Into View
11+
[Setup] Go To Page "scroll/index.html"
12+
${initial_postion}= Get Vertical Position css:#target
13+
Scroll Element Into View css:#target
14+
${postion}= Get Vertical Position css:#target
15+
Should Be True ${initial_postion} > ${postion}
16+
Element Should Contain css:#result ${TEXT}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<html>
2+
<head>
3+
<title>Scroll Keyword Testbed</title>
4+
</head>
5+
<style>
6+
.table {
7+
width: 250px;
8+
max-height:50px;
9+
overflow: scroll
10+
}
11+
.option {
12+
height:24px;
13+
border-bottom: 1px solid black;
14+
}
15+
</style>
16+
<body>
17+
<div class="table" onscroll="setText">
18+
<div class="option">Div 1</div>
19+
<div class="option">Div 2</div>
20+
<div class="option">Div 3</div>
21+
<div class="option">Div 4</div>
22+
<div class="option">Div 5</div>
23+
<div class="option">Div 6</div>
24+
<div class="option">Div 7</div>
25+
<div id="target" class="option">Div 8</div>
26+
</div>
27+
<div id="result">
28+
29+
</div>
30+
<script type="text/javascript">
31+
document.querySelector(".table").onscroll = function() {myFunction()};
32+
function myFunction() {
33+
document.querySelector("#result").innerHTML = "You scrolled in div.";
34+
}
35+
</script>
36+
</body>
37+
</html>

src/SeleniumLibrary/keywords/element.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,18 @@ def focus(self, locator):
511511
"""Deprecated. Use `Set Focus To Element` instead."""
512512
self.set_focus_to_element(locator)
513513

514+
@keyword
515+
def scroll_element_into_view(self, locator):
516+
"""Scrolls an element identified by ``locator`` into view.
517+
518+
See the `Locating elements` section for details about the locator
519+
syntax.
520+
521+
New in SeleniumLibrary 3.2.0
522+
"""
523+
element = self.find_element(locator)
524+
ActionChains(self.driver).move_to_element(element).perform()
525+
514526
@keyword
515527
def drag_and_drop(self, locator, target):
516528
"""Drags element identified by ``locator`` into ``target`` element.

0 commit comments

Comments
 (0)