def find_element_by_xpath(self, xpath): """Finds an element by xpath.""" try: elem_id = self._command("selectElementUsingXPath", xpath) elem = WebElement(self, elem_id) except ErrorInResponseException, ex: utils.handle_find_element_exception(ex)
def find_element_by_link_text(self, link_text): """Finds element by link text.""" try: return WebElement(self, self._command("findElementsByLinkText", link_text).split(",")[0]) except ErrorInResponseException, ex: utils.handle_find_element_exception(ex)
def _find_elements_by(self, selector, key): try: elem_ids = self._command("selectElementsUsing%s" % selector, key) elems = [] if len(elem_ids): for elem_id in elem_ids.split(","): elem = WebElement(self, elem_id) elems.append(elem) return elems except ErrorInResponseException, ex: utils.handle_find_element_exception(ex)
def find_element_by_link_text(self, link): """Finds an element by its link text. throws NoSuchElementException when no element is found with the link text. """ try: elem_id = self._command("selectElementUsingLink", link) elem = WebElement(self, elem_id) return elem except ErrorInResponseException, ex: utils.handle_find_element_exception(ex)
def find_element_by_partial_link_text(self, text): """Finds an element by a segment of its link text throws NoSuchElementException when no element is found with the link text. """ try: elem_id = self._command("selectElementUsingPartialLinkText", text) elem = WebElement(self, elem_id) return elem except ErrorInResponseException, ex: utils.handle_find_element_exception(ex)
def find_elements_by_xpath(self, xpath): """Finds all the elements for the given xpath query.""" try: elem_ids = self._command("selectElementsUsingXPath", xpath) elems = [] if len(elem_ids): for elem_id in elem_ids.split(","): elem = WebElement(self, elem_id) elems.append(elem) return elems except ErrorInResponseException, ex: utils.handle_find_element_exception(ex)
def _find_elments_by(self, selector, key): try: resp = self._command("findElementsBy%s" % selector, key) if not resp: raise NoSuchElementException("Unable to locate element for %s" % key) elems = [] for elem_id in resp.split(","): elem = WebElement(self._parent, elem_id) elems.append(elem) return elems except ErrorInResponseException, ex: utils.handle_find_element_exception(ex)
def find_elements_by_xpath(self, xpath): """Finds elements within the elements by xpath.""" try: resp = self._command("findElementsByXPath", xpath) if not resp: raise NoSuchElementException( "Unable to locate element for %s" % xpath) elems = [] for elem_id in resp.split(","): elem = WebElement(self._parent, elem_id) elems.append(elem) return elems except ErrorInResponseException, ex: utils.handle_find_element_exception(ex)
def find_elements_by_link_text(self, link): """Finds all elements with the same link text. throws NoSuchElementException when no element is found with the link text. """ try: elem_id_list = self._command("selectElementsUsingLink", link) elem_list = [] for elem_id in elem_id_list.split(","): elem = WebElement(self, elem_id) elem_list.append(elem) return elem_list except ErrorInResponseException, ex: utils.handle_find_element_exception(ex)
def find_elements_by_partial_link_text(self, text): """Finds all elements by a segment of the link text. throws NoSuchElementException when no element is found with the link text. """ try: elem_id_list = self._command("selectElementsUsingPartialLinkText", text) elem_list = [] for elem_id in elem_id_list.split(","): if elem_id: elem = WebElement(self, elem_id) elem_list.append(elem) return elem_list except ErrorInResponseException, ex: utils.handle_find_element_exception(ex)
def find_element_by_name(self, name): """Find element by name.""" try: return self.find_element_by_xpath(".//*[@name = '%s']" % name) except ErrorInResponseException, ex: utils.handle_find_element_exception(ex)
def find_element_by_id(self, id_): """Finds element by id.""" try: return WebElement(self, self._command("findElementById", id_)) except ErrorInResponseException, ex: utils.handle_find_element_exception(ex)
def find_element_by_id(self, id_): """Finds an element by its id.""" try: return self.find_element_by_xpath("//*[@id=\"%s\"]" % id_) except ErrorInResponseException, ex: utils.handle_find_element_exception(ex)