Skip to content

Commit d72372b

Browse files
authored
Selenium 3 move_to_element issue fix with event firing webdriver (robotframework#1438)
Fixes robotframework#1435
1 parent a1fd484 commit d72372b

File tree

4 files changed

+61
-12
lines changed

4 files changed

+61
-12
lines changed

atest/acceptance/2-event_firing_webdriver/event_firing_webdriver.robot

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11
*** Settings ***
22
Library SeleniumLibrary event_firing_webdriver=${CURDIR}/MyListener.py
3+
Resource resource_event_firing_webdriver.robot
34
Suite Setup Open Browser ${FRONT PAGE} ${BROWSER} alias=event_firing_webdriver
45
... remote_url=${REMOTE_URL} desired_capabilities=${DESIRED_CAPABILITIES}
56
Suite Teardown Close All Browsers
67

7-
*** Variable ***
8-
${SERVER}= localhost:7000
9-
${BROWSER}= Chrome
10-
${REMOTE_URL}= ${NONE}
11-
${DESIRED_CAPABILITIES}= ${NONE}
12-
${ROOT}= http://${SERVER}/html
13-
${FRONT_PAGE}= ${ROOT}/
14-
158
*** Test Cases ***
169
Open Browser To Start Page
1710
[Tags] NoGrid
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
*** Variables ***
2+
${SERVER}= localhost:7000
3+
${BROWSER}= Chrome
4+
${REMOTE_URL}= ${NONE}
5+
${DESIRED_CAPABILITIES}= ${NONE}
6+
${ROOT}= http://${SERVER}/html
7+
${FRONT_PAGE}= ${ROOT}/
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
*** Settings ***
2+
Documentation Can be deleted when minimum Selenium version 4.0
3+
Library SeleniumLibrary event_firing_webdriver=${CURDIR}/MyListener.py
4+
Resource resource_event_firing_webdriver.robot
5+
Force Tags NoGrid
6+
Suite Setup Open Browser ${FRONT PAGE} ${BROWSER} alias=event_firing_webdriver
7+
... remote_url=${REMOTE_URL} desired_capabilities=${DESIRED_CAPABILITIES}
8+
9+
*** Test Cases ***
10+
Selenium move_to workaround Click Element At Coordinates
11+
[Documentation] LOG 1:5 DEBUG Workaround for Selenium 3 bug.
12+
Click Element At Coordinates id:some_id 4 4
13+
14+
Selenium move_to workaround Scroll Element Into View
15+
[Documentation] LOG 1:4 DEBUG Workaround for Selenium 3 bug.
16+
Scroll Element Into View id:some_id
17+
18+
Selenium move_to workaround Mouse Out
19+
[Documentation] LOG 1:8 DEBUG Workaround for Selenium 3 bug.
20+
Mouse Out id:some_id
21+
22+
Selenium move_to workaround Mouse Over
23+
[Documentation] LOG 1:5 DEBUG Workaround for Selenium 3 bug.
24+
Mouse Over id:some_id

src/SeleniumLibrary/keywords/element.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,13 @@ def click_element_at_coordinates(self, locator, xoffset, yoffset):
627627
% (locator, xoffset, yoffset))
628628
element = self.find_element(locator)
629629
action = ActionChains(self.driver)
630-
action.move_to_element(element)
630+
# Try/except can be removed when minimum required Selenium is 4.0 or greater.
631+
try:
632+
action.move_to_element(element)
633+
except AttributeError:
634+
self.debug('Workaround for Selenium 3 bug.')
635+
element = element.wrapped_element
636+
action.move_to_element(element)
631637
action.move_by_offset(xoffset, yoffset)
632638
action.click()
633639
action.perform()
@@ -666,7 +672,13 @@ def scroll_element_into_view(self, locator):
666672
New in SeleniumLibrary 3.2.0
667673
"""
668674
element = self.find_element(locator)
669-
ActionChains(self.driver).move_to_element(element).perform()
675+
# Try/except can be removed when minimum required Selenium is 4.0 or greater.
676+
try:
677+
ActionChains(self.driver).move_to_element(element).perform()
678+
except AttributeError:
679+
self.debug('Workaround for Selenium 3 bug.')
680+
element = element.wrapped_element
681+
ActionChains(self.driver).move_to_element(element).perform()
670682

671683
@keyword
672684
def drag_and_drop(self, locator, target):
@@ -732,7 +744,14 @@ def mouse_out(self, locator):
732744
offsetx = (size['width'] / 2) + 1
733745
offsety = (size['height'] / 2) + 1
734746
action = ActionChains(self.driver)
735-
action.move_to_element(element).move_by_offset(offsetx, offsety)
747+
# Try/except can be removed when minimum required Selenium is 4.0 or greater.
748+
try:
749+
action.move_to_element(element)
750+
except AttributeError:
751+
self.debug('Workaround for Selenium 3 bug.')
752+
element = element.wrapped_element
753+
action.move_to_element(element)
754+
action.move_by_offset(offsetx, offsety)
736755
action.perform()
737756

738757
@keyword
@@ -745,7 +764,13 @@ def mouse_over(self, locator):
745764
self.info("Simulating Mouse Over on element '%s'." % locator)
746765
element = self.find_element(locator)
747766
action = ActionChains(self.driver)
748-
action.move_to_element(element).perform()
767+
# Try/except can be removed when minimum required Selenium is 4.0 or greater.
768+
try:
769+
action.move_to_element(element).perform()
770+
except AttributeError:
771+
self.debug('Workaround for Selenium 3 bug.')
772+
element = element.wrapped_element
773+
action.move_to_element(element).perform()
749774

750775
@keyword
751776
def mouse_up(self, locator):

0 commit comments

Comments
 (0)