Skip to content

Commit

Permalink
Merge 8e68056 into e5e15e2
Browse files Browse the repository at this point in the history
  • Loading branch information
Milan Falešník committed Jan 11, 2018
2 parents e5e15e2 + 8e68056 commit 86097d8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
34 changes: 32 additions & 2 deletions src/widgetastic/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from cached_property import cached_property
from collections import namedtuple
from jsmin import jsmin
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
Expand All @@ -20,7 +21,8 @@

from .exceptions import (
NoSuchElementException, UnexpectedAlertPresentException, MoveTargetOutOfBoundsException,
StaleElementReferenceException, NoAlertPresentException, LocatorNotImplemented)
StaleElementReferenceException, NoAlertPresentException, LocatorNotImplemented,
WebDriverException)
from .log import create_widget_logger, null_logger
from .xpath import normalize_space
from .utils import crop_string_middle
Expand Down Expand Up @@ -172,6 +174,10 @@ def handles_alerts(self):
handling functions do nothing."""
return self.selenium.capabilities.get('handlesAlerts', True)

@property
def browser_type(self):
return self.selenium.capabilities.get('browserName')

@property
def browser(self):
"""Implemented so :py:class:`widgetastic.widget.View` does not have to check the
Expand Down Expand Up @@ -461,6 +467,15 @@ def move_to_element(self, locator, *args, **kwargs):
raise MoveTargetOutOfBoundsException(
"Despite all the workarounds, scrolling to `{}` was unsuccessful.".format(
locator))
except WebDriverException as e:
# Handling Edge weirdness
if self.browser_type == 'MicrosoftEdge' and 'Invalid argument' in e.msg:
# Moving to invisible element triggers a WebDriverException instead of the former
# MoveTargetOutOfBoundsException with NORMAL, SANE BROWSERS.
pass
else:
# Something else, never let it sink
raise
return el

def drag_and_drop(self, source, target):
Expand Down Expand Up @@ -536,8 +551,23 @@ def classes(self, locator, *args, **kwargs):
Returns:
A :py:class:`set` of strings with classes.
"""
if self.browser_type in {'MicrosoftEdge', 'internet explorer'}:
# Kudos to psav who put together this little script
command = jsmin('''\
return (
function(arguments){
var arr=[];
var le=arguments[0].classList.length;
for (i=0; i < le; i++){
arr.push(arguments[0].classList[i]);
};
return arr;
})(arguments)''')
else:
command = 'return arguments[0].classList;'
result = set(self.execute_script(
"return arguments[0].classList;", self.element(locator, *args, **kwargs), silent=True))
command, self.element(locator, *args, **kwargs),
silent=True))
self.logger.debug('css classes for %r => %r', locator, result)
return result

Expand Down
2 changes: 1 addition & 1 deletion src/widgetastic/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from selenium.common.exceptions import ( # NOQA
NoSuchElementException, MoveTargetOutOfBoundsException, StaleElementReferenceException, # NOQA
NoAlertPresentException, UnexpectedAlertPresentException) # NOQA
NoAlertPresentException, UnexpectedAlertPresentException, WebDriverException) # NOQA


class LocatorNotImplemented(NotImplementedError):
Expand Down

0 comments on commit 86097d8

Please sign in to comment.