def find_element_by_locator(self, locator): locator_type = locator[:locator.find('=')] if locator_type == "": raise InvalidLocatorString(locator) locator_value = locator[locator.find('=')+1:] if locator_type == "id": return WebElement(self.find_element_by_id(locator_value)) elif locator_type == 'class': return WebElement(self.find_element_by_class_name(locator_value)) elif locator_type == 'css': return WebElement(self.find_element_by_css_selector(locator_value)) elif locator_type == 'xpath': return WebElement(self.find_element_by_xpath(locator_value)) else: raise InvalidLocatorString(locator)
def find_elements_by_locator(self, locator): locator_type = locator[:locator.find('=')] if locator_type == "": raise InvalidLocatorString(locator) locator_value = locator[locator.find('=')+1:] if locator_type == 'id': elements = self.find_elements_by_id(locator_value) elif locator_type == 'class': elements = self.find_elements_by_class_name(locator_value) elif locator_type == 'css': elements = self.find_elements_by_css_selector(locator_value) elif locator_type == 'xpath': elements = self.find_elements_by_xpath(locator_value) else: raise InvalidLocatorString(locator) return (WebElement(e) for e in elements)
def __set__(self, val): s = SeleniumSelect(self.driver.find_element_by_locator(self.locator)) method = val[:val.find("=")] value = val[val.find("=") + 1:] if method == "value": s.select_by_value(value) elif method == "index": s.select_by_index(value) elif method == "text": s.select_by_visible_text(value) else: raise InvalidLocatorString(value)
def find_elements_by_locator(self, locator): locator_type, locator_value = locator.split('=') if locator_type == 'id': elements = self.find_elements_by_id(locator_value) elif locator_type == 'class': elements = self.find_elements_by_class_name(locator_value) elif locator_type == 'tag': elements = self.find_elements_by_tag_name(locator_value) elif locator_type == 'css': elements = self.find_elements_by_css_selector(locator_value) elif locator_type == 'xpath': elements = self.find_elements_by_xpath(locator_value) else: raise InvalidLocatorString(locator) return [WebElement(e) for e in elements]
def find_elements_by_locator(self, locator): locator_type = locator[:locator.find('=')] if locator_type == '': raise framework.exceptions.InvalidLocatorString(locator) locator_value = locator[locator.find('=') + 1:] if locator_type == 'id': elements = self.find_elements_by_id(locator_value) elif locator_type == 'class': elements = self.find_elements_by_class_name(locator_value) elif locator_type == 'tag': elements = self.find_elements_by_tag_name(locator_value) elif locator_type == 'css': elements = self.find_elements_by_css_selector(locator_value) elif locator_type == 'xpath': elements = self.find_elements_by_xpath(locator_value) else: raise InvalidLocatorString(locator) return [WebElement(e) for e in elements]