コード例 #1
0
    def sendKeys(self,
                 el: WebElement,
                 keys,
                 clearBefore: bool = False,
                 assertText: str = None,
                 assertAttempts: int = 3,
                 assertTime: float = 1,
                 timeSleep: float = 0) -> bool:
        """
        -> Send keys to an element and optionally assert for a text on page after the send
        :return: True/False. True if send keys and then page has the text, False otherwise
        """
        if el is None:
            return False  #1

        try:
            if clearBefore:
                el.click()
                el.clear()
            if isinstance(keys, str):  #->2
                el.send_keys(keys)
            elif isinstance(keys, tuple):  #->3
                for k in keys:
                    el.send_keys(k)
            else:
                return False  #4
        except:
            return False  #5
        time.sleep(timeSleep)
        return self.assertText(assertText, assertAttempts,
                               assertTime)  #2 and 3
コード例 #2
0
 def fill_input_with_value(input_el: WebElement, value: InputValue) -> None:
     try:
         # If element is user-editable, clear input.
         input_el.clear()
     except InvalidElementStateException:
         pass
     input_el.send_keys(value)
コード例 #3
0
 def clear_element(self,
                   locator_type: By = None,
                   locator_value: str = None,
                   element: WebElement = None,
                   from_element: WebElement = None,
                   time_to_wait: int = TIME_TO_WAIT):
     if not element:
         element = self.find_element_by(locator_type, locator_value,
                                        from_element, time_to_wait)
     element.clear()
コード例 #4
0
ファイル: conftest.py プロジェクト: zulygs/omegaup
    def send_keys(self,  # pylint: disable=no-self-use
                  element: WebElement,
                  value: str,
                  retries: int = 10) -> None:
        '''Helper to _really_ send keys to an element.

        For some yet unexplained reason when running in non-headless mode, the
        interactions with text elements do not always register by the browser.
        This causes input elements to remain empty even after sending the keys.

        This method sends the keys and then ensures that the value of the
        element is the expected string, retrying if necessary.
        '''

        for _ in range(retries):
            element.clear()
            element.send_keys(value)
            if element.get_attribute('value') == value:
                return
        logging.error('Failed to send keys to the element')
コード例 #5
0
ファイル: executor.py プロジェクト: quickstrom/pyquickstrom
 def perform_action(driver, action):
     try:
         if action.id == 'noop':
             pass
         elif action.id == 'click':
             id = action.args[0]
             element = WebElement(driver, id)
             ActionChains(driver).move_to_element(element).click(
                 element).perform()
         elif action.id == 'doubleClick':
             id = action.args[0]
             element = WebElement(driver, id)
             ActionChains(driver).move_to_element(
                 element).double_click(element).perform()
         elif action.id == 'focus':
             id = action.args[0]
             element = WebElement(driver, id)
             element.send_keys("")
         elif action.id == 'keyPress':
             char = action.args[0]
             element = driver.switch_to.active_element
             element.send_keys(char)
         elif action.id == 'enterText':
             element = driver.switch_to.active_element
             element.send_keys(action.args[0])
         elif action.id == 'enterTextInto':
             id = action.args[1]
             element = WebElement(driver, id)
             element.send_keys(action.args[0])
         elif action.id == 'clear':
             id = action.args[0]
             element = WebElement(driver, id)
             element.clear()
         else:
             raise UnsupportedActionError(action)
     except Exception as e:
         raise PerformActionError(action, e)
コード例 #6
0
    def robust_input(self,
                     ele: WebElement,
                     text: str,
                     use_paste=False,
                     ensure_value=False) -> bool:
        ele.clear()
        if use_paste:
            import os
            os.system("echo {}|clip".format(text))
            ele.send_keys(Keys.CONTROL, "v")
        else:
            ele.send_keys(text)

        if ensure_value:
            if ele.get_attribute("value") == text:
                return True
            else:
                logger_driver.warning({
                    "target input": text,
                    "inputted": ele.get_attribute("value")
                })
                return False
        else:
            return True
コード例 #7
0
ファイル: basepage.py プロジェクト: miracleAi/doubanTest
 def set_element_value(self, element: WebElement, key):
     element.clear()
     element.click()
     element.send_keys(key)