def set_customize_attribute_for_element_by_js(self, attribute, value): """Please use xpath for the element you want to set value""" elementXpath = self.locator() positionXpath = elementXpath.find("xpath=") if positionXpath != -1: elementLocator = elementXpath[6:] driver.execute_javascript( "document.evaluate(\"" + elementLocator + "\", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue." + attribute + " = \"" + value + "\"")
def get_tree_icon_status(self): self.treeIcon.wait_until_element_is_visible() status = driver.execute_javascript("return window.getComputedStyle(arguments[0]).backgroundPositionX", self.treeIcon.get_webelement()) if status == "-54px": return "collapsed" elif status == "-72px": return "expanded" else: return "empty"
def is_element_visible(self): try: return driver.execute_javascript( "function isVisible(e){var t=e.getBoundingClientRect()," + "n=document.elementFromPoint(t.x+t.width/2,t.y+t.height/2)," + "i=!1;for(let t=0;t<3;t++)e==n?i=!0:n=n.parentElement;return i}" + "return isVisible(arguments[0]);", self.get_webelement()) except: return False
def _get_latest_download_file_name(self): return driver.execute_javascript(self.downloadFileNameJs.locator())
def _get_element_js_property(self, element, selectedProperty): newLocator = element.locator().replace('xpath=', '') newJsStr = "return window.document.evaluate(\"" + newLocator + "\",document.body,null,9,null).singleNodeValue." + selectedProperty return driver.execute_javascript(newJsStr)
def close_current_tab(self): driver.execute_javascript("window.close()")
def open_new_tab(self, url): driver.execute_javascript("window.open('')") driver.switch_window("title=undefined") driver.go_to(url)
def click_element_by_js(self): driver.execute_javascript("arguments[0].click();", self.get_webelement())