Skip to content

Commit 9296227

Browse files
[py] Add Element Not Interactable exception
This adds the Element Not Interactable exception that is being raised by W3C Compliant Remote Ends.
1 parent 3cfe188 commit 9296227

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

py/selenium/common/exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ class ElementNotVisibleException(InvalidElementStateException):
164164
pass
165165

166166

167+
class ElementNotInteractableException(InvalidElementStateException):
168+
"""
169+
Thrown when an element is present in the DOM but interactions
170+
with that element will hit another element do to paint order
171+
"""
172+
pass
173+
174+
167175
class ElementNotSelectableException(InvalidElementStateException):
168176
"""
169177
Thrown when trying to select an unselectable element.

py/selenium/webdriver/remote/errorhandler.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
from selenium.common.exceptions import (ElementNotSelectableException,
18+
from selenium.common.exceptions import (ElementNotInteractableException,
19+
ElementNotSelectableException,
1920
ElementNotVisibleException,
2021
ErrorInResponseException,
2122
InvalidElementStateException,
@@ -29,6 +30,7 @@
2930
NoAlertPresentException,
3031
StaleElementReferenceException,
3132
TimeoutException,
33+
UnexpectedAlertPresentException,
3234
WebDriverException)
3335

3436
try:
@@ -50,6 +52,7 @@ class ErrorCode(object):
5052
ELEMENT_NOT_VISIBLE = [11, 'element not visible']
5153
INVALID_ELEMENT_STATE = [12, 'invalid element state']
5254
UNKNOWN_ERROR = [13, 'unknown error']
55+
ELEMENT_NOT_INTERACTABLE = ["element not interactable"]
5356
ELEMENT_IS_NOT_SELECTABLE = [15, 'element not selectable']
5457
JAVASCRIPT_ERROR = [17, 'javascript error']
5558
XPATH_LOOKUP_ERROR = [19, 'invalid selector']
@@ -133,6 +136,8 @@ def check_response(self, response):
133136
exception_class = InvalidSelectorException
134137
elif status in ErrorCode.ELEMENT_IS_NOT_SELECTABLE:
135138
exception_class = ElementNotSelectableException
139+
elif status in ErrorCode.ELEMENT_NOT_INTERACTABLE:
140+
exception_class = ElementNotInteractableException
136141
elif status in ErrorCode.INVALID_COOKIE_DOMAIN:
137142
exception_class = WebDriverException
138143
elif status in ErrorCode.UNABLE_TO_SET_COOKIE:

py/test/selenium/webdriver/common/visibility_tests.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from selenium.common.exceptions import (
2121
ElementNotVisibleException,
22+
ElementNotInteractableException,
2223
InvalidElementStateException)
2324
from selenium.webdriver.common.by import By
2425

@@ -67,30 +68,42 @@ def testHiddenInputElementsAreNeverVisible(driver, pages):
6768
def testShouldNotBeAbleToClickOnAnElementThatIsNotDisplayed(driver, pages):
6869
pages.load("javascriptPage.html")
6970
element = driver.find_element(by=By.ID, value="unclickable")
70-
with pytest.raises(ElementNotVisibleException):
71+
try:
7172
element.click()
73+
assert 1 == 0, "should have thrown an exception"
74+
except (ElementNotVisibleException, ElementNotInteractableException) as e:
75+
pass
7276

7377

7478
def testShouldNotBeAbleToToggleAnElementThatIsNotDisplayed(driver, pages):
7579
pages.load("javascriptPage.html")
7680
element = driver.find_element(by=By.ID, value="untogglable")
77-
with pytest.raises(ElementNotVisibleException):
81+
try:
7882
element.click()
83+
assert 1 == 0, "should have thrown an exception"
84+
except (ElementNotVisibleException, ElementNotInteractableException) as e:
85+
pass
7986

8087

8188
def testShouldNotBeAbleToSelectAnElementThatIsNotDisplayed(driver, pages):
8289
pages.load("javascriptPage.html")
8390
element = driver.find_element(by=By.ID, value="untogglable")
84-
with pytest.raises(ElementNotVisibleException):
91+
try:
8592
element.click()
93+
assert 1 == 0, "should have thrown an exception"
94+
except (ElementNotVisibleException, ElementNotInteractableException) as e:
95+
pass
8696

8797

8898
@pytest.mark.xfail_phantomjs(raises=InvalidElementStateException)
8999
def testShouldNotBeAbleToTypeAnElementThatIsNotDisplayed(driver, pages):
90100
pages.load("javascriptPage.html")
91101
element = driver.find_element(by=By.ID, value="unclickable")
92-
with pytest.raises(ElementNotVisibleException):
102+
try:
93103
element.send_keys("You don't see me")
104+
assert 1 == 0, "should have thrown an exception"
105+
except (ElementNotVisibleException, ElementNotInteractableException) as e:
106+
pass
94107
assert element.get_attribute("value") != "You don't see me"
95108

96109

0 commit comments

Comments
 (0)