Skip to content

Instantly share code, notes, and snippets.

@maratori
Created September 17, 2018 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maratori/0da1f2d3ca6077fa51ef7010a0fac8f1 to your computer and use it in GitHub Desktop.
Save maratori/0da1f2d3ca6077fa51ef7010a0fac8f1 to your computer and use it in GitHub Desktop.
Workaround for bug in SafariDriver with overflow hidden
import allure
from selene.abctypes.webelement import IWebElement
from selene.browser import execute_script
from selene.conditions import Visible
from selene.exceptions import ConditionMismatchException
@allure.step("Hack selene library to introduce workaroud bug in SafariDriver")
def hackSafariDriver():
""" Workaround for bug https://github.com/SeleniumHQ/selenium/issues/4456 """
# noinspection PyUnusedLocal
def hackedMatch(self, webelement: IWebElement) -> IWebElement:
if not webelement.is_displayed():
if execute_script("return getComputedStyle(arguments[0]).overflowX=='hidden'", webelement):
id_ = webelement.get_attribute("id")
class_ = webelement.get_attribute("class")
element = "<{}{}{}>".format(webelement.tag_name,
" id='{}'".format(id_) if id_ else "",
" class='{}'".format(class_) if class_ else "")
with allure.step("Set overflowX='overlay' for element {}".format(element)):
execute_script("arguments[0].style.overflowX='overlay'", webelement)
if not webelement.is_displayed():
raise ConditionMismatchException()
return webelement
Visible.match = hackedMatch
@maratori
Copy link
Author

This is a workaround for issue #SeleniumHQ/selenium/issues/4456 for selene library in Python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment