def jsDouble_click(self):
     """
     doubleclick this element with js script
     """
     log.info("clicking " + self.selector.statement)
     self.RunJS("arguments[0].click();arguments[0].click();",
                "js click failed")
Exemple #2
0
def WaitForResult(Function, *args):
    """
    wait for Function to return a not-None value and returns it    
    *args - function args
    timeout - as defined at TimeoutManager
    """
    total = 0
    attempt = 0
    timeout, sleep_time = TimeoutManager.Get()
    log.info("WaitForResult " + str(Function))
    while (total < timeout):
        # if attempt != 1:
        #    log.Quiet()
        result = Function(*args)
        if result:
            # log.Noise()
            return result

        if attempt == 0:
            log.debug("\nretrying...")
        else:
            log.debug(str(attempt) + "..")
        sleep(sleep_time)
        total += (sleep_time + TimeoutManager._implicit_wait)
        attempt += 1
    # log.Noise()
    return False
    def RunJS(self, script, failMassage, sensitive=False):
        """
        running javascript with this element as arguments[0]
        """
        log.info("RunJS:" + script)
        try:

            self.driver.execute_script(script, self)
        except Exception as e:
            if sensitive:
                raise e
            else:
                log.fail(self.selector.statement + failMassage)
                log.info("   " + str(e))
    def get_text(self):
        """
        get text of current element using
        either 'text' or 'innerHTML' attributes
        """
        from selenium.common.exceptions import StaleElementReferenceException
        for i in range(0, 2):
            try:
                if (super().text):
                    return super().text
                elif (super().get_attribute('innerHTML')):
                    return (super().get_attribute('innerHTML'))

            # TODO this approch can be usfull at more places
            except StaleElementReferenceException:
                log.info("iz.get_text: re-finding stale element " +
                         self.selector.statement)
                self = self.driver.find(self.selector)
        return None
 def _find(self, selector: Selector, sensitive, root=None):
     """
     internal use only
     """
     log.info("finding " + str(selector))
     if (root):
         findfunction = root
     else:
         findfunction = self.find_element
     # func =   findFunctions[selector.method]
     element = actionWrapper(findfunction, None, [self.accept_alert],
                             "find element failed. ", selector.method,
                             selector.statement)
     if element:
         log.info("find - success")
         if (type(element) is list):
             return izWebElement.ConvertList(element, selector, self)
         else:
             return izWebElement(element, selector, self)
     else:
         if sensitive:
             raise AssertionError(f"find - failed: [{selector.statement}].")
Exemple #6
0
 def execute(self):
     log.info("RUNNING: " + self.text)
     self.proc = subprocess.Popen(self.text)
     self.proc.wait()
 def waitNexist(self):
     """
     wait for this elements to disappear 
     according to izSelenium.TimeOutManager
     """
     timeouts = TM.Get()
     sleep_time = timeouts[1]
     total = 0
     attempt = 0
     timeout = 15
     while (total < timeout):
         try:
             if ((super().is_displayed() or super().rect)):
                 sleep(sleep_time)
                 total += (sleep_time + TM._implicit_wait)
             else:
                 log.info("WaitNExist success - element not on screen")
                 return True
         except StaleElementReferenceException:
             log.info("WaitNExist success - element is stale")
             return True
         except NoSuchElementException:
             log.info("WaitNExist success - no such element")
             return True
         except ElementNotVisibleException:
             log.info("WaitNExist success - element not visible")
             return True
         except Exception as e:
             log.info(f"WaitNExist propably success: \n{e}")
             return True
         finally:
             attempt += 1
     log.info("WaitNExist fail - element still here after " + str(total) +
              "seconds")
     return False