from bfs.bfs10060.bfs10173 import bfs10175
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 bfs10273(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, bfs10232):
    return (self.target == bfs10232.target)

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


class bfs10274(bfs10273):
  def __init__(self, target):
    super(bfs10274, self).__init__(target)
    self.bfs10275 = None

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

  def bfs10300(self, web_element):
    if (not self.bfs10275):
      return 0

    if hasattr(self.bfs10275, 'location'):
      try:
        bfs10276 = self.bfs10275.location
      except StaleElementReferenceException:
        return 0
      else:
        return bfs10276.bfs10253(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, bfs10104):
    return (self.target.find_elements_by_xpath(bfs10104) or [])

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

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

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

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


@decorator
def bfs10305(bfs10030, *args, **bfs10066):
  try:
    return bfs10030(*args, **bfs10066)
  except URLError as bfs10304:
    if bfs10306(bfs10304):
      raise StaleElementReferenceException('The Selenium server this element belonged to is no longer available.')
    else:
      raise 



def bfs10306(bfs10304):
  try:
    bfs10307 = 10061
    return (bfs10304.args[0][0] == bfs10307)
  except (IndexError, TypeError):
    return False


class bfs10311(bfs10273):
  def __init__(self, target):
    super(bfs10311, self).__init__(target)
    self.bfs10310 = None

  @property
  @bfs10305
  def location(self):
    if (self.bfs10310 is None):
      location = self.target.location
      (x, y) = (location['x'], location['y'])
      size = self.target.size
      (width, height) = (size['width'], size['height'])
      self.bfs10310 = bfs10175(x, y, width, height)

    return self.bfs10310

  def is_displayed(self):
    try:
      return (self.target.is_displayed() and self.location.bfs10227(bfs10175(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 bfs10312(object):
  def __init__(self, driver, bfs10314=None):
    if (bfs10314 is None):
      bfs10314 = []

    self.driver = driver
    self.bfs10314 = bfs10314

  def __iter__(self):
    yield []
    bfs10313 = 0
    while True:
      try:
        self.driver.switch_to.frame(bfs10313)
      except (StaleElementReferenceException, NoSuchFrameException):
        break
      else:
        bfs10315 = (self.bfs10314 + [bfs10313])
        for bfs10063 in bfs10312(self.driver, bfs10315):
          yield ([bfs10313] + bfs10063)

        self.switch_to_frame(self.bfs10314)
        bfs10313 += 1



  def switch_to_frame(self, bfs10317):
    self.driver.switch_to.default_content()
    for bfs10316 in bfs10317:
      self.driver.switch_to.frame(bfs10316)



