def __init__(self, key, cacheable=False):

        self.locator = None
        self.by = None
        self.description = None
        self._parent_element = None
        self._listeners = []
        self.cacheable = cacheable

        if isinstance(key, str) and len(key) > 0:
            value = ConfigurationsManager().get_str_for_key(key,
                                                            default_value=key)
            #print("30"+value+" loading")
            try:
                locator = json.loads(value)['locator']
                # self.description = json.loads(value)['description']
            except ValueError:
                locator = value
                # self.description = value
            parent = base_driver.BaseDriver().get_driver()
            self.by, self.locator = get_find_by(locator)
            if parent.w3c and parent._is_remote is False:
                if self.by == By.ID:
                    self.by = By.CSS_SELECTOR
                    self.locator = '[id="%s"]' % self.locator
                elif self.by == By.TAG_NAME:
                    self.by = By.CSS_SELECTOR
                elif self.by == By.CLASS_NAME:
                    self.by = By.CSS_SELECTOR
                    self.locator = ".%s" % self.locator
                elif self.by == By.NAME:
                    self.by = By.CSS_SELECTOR
                    self.locator = '[name="%s"]' % self.locator
            self.description = self.locator
            self.cacheable = cacheable
            self._id = -1
            RemoteWebElement.__init__(self,
                                      parent=parent,
                                      id_=self.id,
                                      w3c=parent.w3c)

        if ConfigurationsManager().contains_key(
                ApplicationProperties.WEBELEMENT_COMMAND_LISTENERS):
            class_name = ConfigurationsManager().get_str_for_key(
                ApplicationProperties.WEBELEMENT_COMMAND_LISTENERS)
            self._listeners.append(load_class(class_name)())
Esempio n. 2
0
 def __init__(self, we):
     WebElement.__init__(self, we.parent, we.id, True)