Python selenium.webdriver.support.expected_conditions.text_to_be_present_in_element_value() Examples

The following are 12 code examples of selenium.webdriver.support.expected_conditions.text_to_be_present_in_element_value(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module selenium.webdriver.support.expected_conditions , or try the search function .
Example #1
Source File: WebRunner.py    From PyWebRunner with MIT License 6 votes vote down vote up
def _wait_for(self, wait_function, **kwargs):
        '''
        Wrapper to handle the boilerplate involved with a custom wait.

        Parameters
        ----------
        wait_function: func
            This can be a builtin selenium wait_for class,
            a special wait_for class that implements the __call__ method,
            or a lambda function
        timeout: int
            The number of seconds to wait for the given condition
            before throwing an error.
            Overrides WebRunner.timeout

        '''
        try:
            wait = WebDriverWait(self.browser, kwargs.get('timeout') or self.timeout)
            wait.until(wait_function)
        except TimeoutException:
            if self.driver == 'Gecko':
                print("Geckodriver can't use the text_to_be_present_in_element_value wait for some reason.")
            else:
                raise 
Example #2
Source File: WebRunner.py    From PyWebRunner with MIT License 6 votes vote down vote up
def wait_for_text_in_value(self, selector='', text='', **kwargs):
        '''
        Wait for an element's value to contain a specific string.

        Parameters
        ----------
        selector: str
            A CSS selector to search for. This can be any valid CSS selector.

        text: str
            The string to look for. This must be precise.
            (Case, punctuation, UTF characters... etc.)
        kwargs:
            Passed on to _wait_for

        '''
        if selector.startswith('/'):
            by = By.XPATH
        else:
            by = By.CSS_SELECTOR
        self._wait_for(EC.text_to_be_present_in_element_value((by, selector),
                                                              text), **kwargs) 
Example #3
Source File: WebRunner.py    From PyWebRunner with MIT License 6 votes vote down vote up
def wait_for_value(self, selector='', value='', **kwargs):
        '''
        Wait for an element to contain a specific string.

        Parameters
        ----------
        selector: str
            A CSS selector to search for. This can be any valid CSS selector.

        value: str
            The string to look for. This must be precise.
            (Case, punctuation, UTF characters... etc.)
        kwargs:
            Passed on to _wait_for

        '''
        if selector.startswith('/'):
            by = By.XPATH
        else:
            by = By.CSS_SELECTOR
        self._wait_for(EC.text_to_be_present_in_element_value((by, selector),
                                                              value), **kwargs) 
Example #4
Source File: accounts.py    From PTCAccount2 with MIT License 6 votes vote down vote up
def _default_captcha_handler(driver):
    print("[Captcha Handler] Please enter the captcha in the browser window...")
    elem = driver.find_element_by_class_name("g-recaptcha")
    driver.execute_script("arguments[0].scrollIntoView(true);", elem)

    # Waits for you to input captcha
    wait_time_in_sec = 600
    try:
        WebDriverWait(driver, wait_time_in_sec).until(
            EC.text_to_be_present_in_element_value((By.ID, "g-recaptcha-response"), ""))
    except TimeoutException:
        driver.quit()
        print("Captcha was not entered within %s seconds." % wait_time_in_sec)
        return False  # NOTE: THIS CAUSES create_account TO RUN AGAIN WITH THE EXACT SAME PARAMETERS

    print("Captcha successful. Sleeping for 1 second...")
    time.sleep(1)  # Workaround for captcha detecting instant submission? Unverified
    return True 
Example #5
Source File: captcha_handler.py    From PokemonGo-Bot with MIT License 5 votes vote down vote up
def get_token(self, url):
        token = ''
        path = os.getcwd()
        if _platform == "Windows" or _platform == "win32":
            # Check if we are on 32 or 64 bit
            file_name= 'chromedriver.exe'
        if _platform.lower() == "darwin":
            file_name= 'chromedriver'
        if _platform.lower() == "linux" or _platform.lower() == "linux2":
            file_name = 'chromedriver'
            
        full_path = ''
        if os.path.isfile(path + '/' + file_name): # check local dir first
            full_path = path + '/' + file_name

        if full_path == '':
            self.bot.logger.error(file_name + ' is needed for manual captcha solving! Please place it in the bots root directory')
            sys.exit(1)
        
        try:
            driver = webdriver.Chrome(full_path)
            driver.set_window_size(600, 600)
        except Exception:
            self.bot.logger.error('Error with Chromedriver, please ensure it is the latest version.')
            sys.exit(1)
            
        driver.get(url)
        
        elem = driver.find_element_by_class_name("g-recaptcha")
        driver.execute_script("arguments[0].scrollIntoView(true);", elem)
        self.bot.logger.info('You have 1 min to solve the Captcha')
        try:
            WebDriverWait(driver, 60).until(EC.text_to_be_present_in_element_value((By.NAME, "g-recaptcha-response"), ""))
            token = driver.execute_script("return grecaptcha.getResponse()")
            driver.close()
        except TimeoutException, err:
            self.bot.logger.error('Timed out while trying to solve captcha') 
Example #6
Source File: tests.py    From GTDWeb with GNU General Public License v2.0 5 votes vote down vote up
def wait_for_value(self, css_selector, text, timeout=10):
        """
        Helper function that blocks until the value is found in the CSS selector.
        """
        from selenium.webdriver.common.by import By
        from selenium.webdriver.support import expected_conditions as ec
        self.wait_until(
            ec.text_to_be_present_in_element_value(
                (By.CSS_SELECTOR, css_selector), text),
            timeout
        ) 
Example #7
Source File: tests.py    From bioforum with MIT License 5 votes vote down vote up
def wait_for_value(self, css_selector, text, timeout=10):
        """
        Block until the value is found in the CSS selector.
        """
        from selenium.webdriver.common.by import By
        from selenium.webdriver.support import expected_conditions as ec
        self.wait_until(
            ec.text_to_be_present_in_element_value(
                (By.CSS_SELECTOR, css_selector), text),
            timeout
        ) 
Example #8
Source File: utils.py    From opencraft with GNU Affero General Public License v3.0 5 votes vote down vote up
def fill_form(self, form_data, validate_fields=None):
        """
        Fill in the form with the given data.
        """
        validate_fields = validate_fields or ()
        for field, value in form_data.items():
            element = self.form.find_element_by_name(field)
            if element.get_attribute('type') == 'checkbox':
                if bool(value) != element.is_selected():
                    element.click()
                    # Before moving on, make sure checkbox state (checked/unchecked) corresponds to desired value
                    WebDriverWait(self.client, timeout=5) \
                        .until(expected_conditions.element_selection_state_to_be(element, value))
                continue

            if element.get_attribute('type') == 'color':
                # Selenium doesn't support typing into HTML5 color field with send_keys
                id_elem = element.get_attribute('id')
                self.client.execute_script("document.getElementById('{}').type='text'".format(id_elem))

            if not element.get_attribute('readonly') and not element.get_attribute('type') == 'hidden':
                element.clear()
                if value:
                    # A small delay is required for angular to properly mark field as dirty
                    element.click()
                    time.sleep(.5)
                    element.send_keys(value)
                    # Before moving on, make sure input field contains desired text
                    WebDriverWait(self.client, timeout=5) \
                        .until(expected_conditions.text_to_be_present_in_element_value((By.NAME, field), value))
                    # And that the server validation, if any, has completed
                    if field in validate_fields:
                        WebDriverWait(self.client, timeout=10) \
                            .until(ServerValidationComplete((By.NAME, field))) 
Example #9
Source File: tests.py    From Hands-On-Application-Development-with-PyCharm with MIT License 5 votes vote down vote up
def wait_for_value(self, css_selector, text, timeout=10):
        """
        Block until the value is found in the CSS selector.
        """
        from selenium.webdriver.common.by import By
        from selenium.webdriver.support import expected_conditions as ec
        self.wait_until(
            ec.text_to_be_present_in_element_value(
                (By.CSS_SELECTOR, css_selector), text),
            timeout
        ) 
Example #10
Source File: tests.py    From python with Apache License 2.0 5 votes vote down vote up
def wait_for_value(self, css_selector, text, timeout=10):
        """
        Helper function that blocks until the value is found in the CSS selector.
        """
        from selenium.webdriver.common.by import By
        from selenium.webdriver.support import expected_conditions as ec
        self.wait_until(
            ec.text_to_be_present_in_element_value(
                (By.CSS_SELECTOR, css_selector), text),
            timeout
        ) 
Example #11
Source File: tests.py    From openhgsenti with Apache License 2.0 5 votes vote down vote up
def wait_for_value(self, css_selector, text, timeout=10):
        """
        Helper function that blocks until the value is found in the CSS selector.
        """
        from selenium.webdriver.common.by import By
        from selenium.webdriver.support import expected_conditions as ec
        self.wait_until(
            ec.text_to_be_present_in_element_value(
                (By.CSS_SELECTOR, css_selector), text),
            timeout
        ) 
Example #12
Source File: tests.py    From python2017 with MIT License 5 votes vote down vote up
def wait_for_value(self, css_selector, text, timeout=10):
        """
        Helper function that blocks until the value is found in the CSS selector.
        """
        from selenium.webdriver.common.by import By
        from selenium.webdriver.support import expected_conditions as ec
        self.wait_until(
            ec.text_to_be_present_in_element_value(
                (By.CSS_SELECTOR, css_selector), text),
            timeout
        )