from bfs.bfs10063.bfs10207 import bfs10210
from decorator import decorator
from selenium.common.exceptions import StaleElementReferenceException, NoSuchFrameException
from selenium.webdriver.common.action_chains import ActionChains
from urllib.error import URLError
import sys
class bfs10346(object):
  def __init__(self, target):
    self.target = target

  def __getattr__(self, item):
    return getattr(self.target, item)

  def unwrap(self):
    return self.target

  def __hash__(self):
    return hash(self.target)

  def __eq__(self, bfs10347):
    return (self.target == bfs10347.target)

  def __ne__(self, bfs10351):
    return (not (self == bfs10351))


class bfs10350(bfs10346):
  def __init__(self, target):
    super(bfs10350, self).__init__(target)
    self.bfs10352 = None

  def bfs10354(self):
    return ActionChains(self.target)

  def bfs10355(self, web_element):
    if (not self.bfs10352):
      return 0

    if hasattr(self.bfs10352, 'location'):
      try:
        bfs10353 = self.bfs10352.location
      except StaleElementReferenceException:
        return 0
      else:
        return bfs10353.bfs10303(web_element.location)

    else:
      return 0


  def find_elements_by_name(self, name):
    return (self.target.find_elements_by_name(name) or [])

  def find_elements_by_xpath(self, bfs10357):
    return (self.target.find_elements_by_xpath(bfs10357) or [])

  def find_elements_by_css_selector(self, bfs10356):
    return (self.target.find_elements_by_css_selector(bfs10356) or [])

  def bfs10360(self):
    return (self.browser_name == 'firefox')

  @property
  def browser_name(self):
    return self.target.capabilities['browserName']

  def bfs10361(self):
    return (self.browser_name == 'internet explorer')


@decorator
def bfs10367(bfs10362, *args, **bfs10364):
  try:
    return bfs10362(*args, **bfs10364)
  except URLError as bfs10363:
    if bfs10365(bfs10363):
      raise StaleElementReferenceException('The Selenium server this element belonged to is no longer available.')
    else:
      raise 



def bfs10365(bfs10366):
  try:
    bfs10370 = 10061
    return (bfs10366.args[0][0] == bfs10370)
  except (IndexError, TypeError):
    return False


class bfs10371(bfs10346):
  def __init__(self, target):
    super(bfs10371, self).__init__(target)
    self.bfs10372 = None

  @property
  @bfs10367
  def location(self):
    if (self.bfs10372 is None):
      location = self.target.location
      (x, y) = (location['x'], location['y'])
      size = self.target.size
      (width, height) = (size['width'], size['height'])
      self.bfs10372 = bfs10210(x, y, width, height)

    return self.bfs10372

  def is_displayed(self):
    try:
      return (self.target.is_displayed() and self.location.bfs10254(bfs10210(0, 0, sys.maxsize, sys.maxsize)))
    except StaleElementReferenceException:
      return False


  def __repr__(self):
    return ('<%s>%s</%s>' % (self.tag_name, self.target.text, self.tag_name))


class bfs10373(object):
  def __init__(self, driver, bfs10374=None):
    if (bfs10374 is None):
      bfs10374 = []

    self.driver = driver
    self.bfs10374 = bfs10374

  def __iter__(self):
    yield []
    for bfs10376 in range(sys.maxsize):
      try:
        self.driver.switch_to.frame(bfs10376)
      except (StaleElementReferenceException, NoSuchFrameException):
        break
      else:
        bfs10375 = (self.bfs10374 + [bfs10376])
        for bfs10377 in bfs10373(self.driver, bfs10375):
          yield ([bfs10376] + bfs10377)

        try:
          self.switch_to_frame(self.bfs10374)
        except NoSuchFrameException:
          raise bfs10400()




  def switch_to_frame(self, bfs10401):
    self.driver.switch_to.default_content()
    for bfs10402 in bfs10401:
      self.driver.switch_to.frame(bfs10402)



class bfs10400(Exception):
  pass

