Python selenium.common.exceptions 模块,ElementNotVisibleException() 实例源码

我们从Python开源项目中,提取了以下11个代码示例,用于说明如何使用selenium.common.exceptions.ElementNotVisibleException()

项目:mos-horizon    作者:Mirantis    | 项目源码 | 文件源码
def _is_element_visible(self, *locator):
        try:
            return self._get_element(*locator).is_displayed()
        except (Exceptions.NoSuchElementException,
                Exceptions.ElementNotVisibleException):
            return False
项目:mos-horizon    作者:Mirantis    | 项目源码 | 文件源码
def _get_element_id(self, *locator):
        try:
            return self.driver.find_element(*locator).id
        except (Exceptions.NoSuchElementException,
                Exceptions.ElementNotVisibleException):
            return None
项目:software-factory    作者:softwarefactory-project    | 项目源码 | 文件源码
def _internal_login(self, driver, user, password):
        switch = None
        count = 0
        while not switch and count < 10:
            t = driver.find_element_by_id("toggle")
            driver.implicitly_wait(1)
            t.click()
            try:
                switch = driver.find_element_by_id('username')
            except ElementNotVisibleException:
                count += 1
        u = driver.find_element_by_id("username")
        u.send_keys(user)
        p = driver.find_element_by_id("password")
        p.send_keys(password)
        p.submit()
项目:software-factory    作者:softwarefactory-project    | 项目源码 | 文件源码
def login_as(self, username, passwd):
        iframe = self.driver.find_element_by_tag_name("iframe")
        self.driver.switch_to.frame(iframe)
        self.driver.find_element_by_id("login-btn").click()
        self.driver.switch_to.default_content()
        switch = None
        count = 0
        while not switch and count < 10:
            t = self.driver.find_element_by_id("toggle")
            self.driver.implicitly_wait(1)
            t.click()
            try:
                switch = self.driver.find_element_by_name('username')
            except ElementNotVisibleException:
                count += 1
        self.driver.find_element_by_name("username").send_keys(username)
        self.driver.find_element_by_name("password").send_keys(passwd)
        self.driver.find_element_by_name("password").submit()
项目:mos-horizon    作者:Mirantis    | 项目源码 | 文件源码
def _is_element_displayed(self, element):
        if element is None:
            return False
        try:
            if isinstance(element, webelement.WebElement):
                return element.is_displayed()
            else:
                return element.src_elem.is_displayed()
        except (Exceptions.ElementNotVisibleException,
                Exceptions.StaleElementReferenceException):
            return False
项目:selenium-toy    作者:blackmatrix7    | 项目源码 | 文件源码
def is_elements_by_xpath(self, xpath):
        """
        ???????????2?????
        :param xpath:
        :return:
        """
        try:
            WebDriverWait(
                driver=self.driver,
                timeout=1,
                poll_frequency=current_config['POLL_FREQUENCY']
            ).until(lambda x: x.find_elements_by_xpath(xpath))
            return True
        except ElementNotVisibleException:
            return False
项目:Job-Automate    作者:mandeep    | 项目源码 | 文件源码
def submit_application(driver, debug=False):
    """Click the apply button and submit the application.

    Positional argument:
    driver -- the Selenium webdriver instance

    Keyword argument:
    debug -- flag used for testing to omit application submission

    There are two types of apply methods: one applies after
    clicking the apply button, and the other applies after clicking the
    continue button and answering some questions. The try/except clause
    clicks the apply button if it exists, otherwise it will click the continue
    button and select the radio buttons that indicate 'Yes'.
    """
    try:
        driver.find_element_by_link_text('Continue').click()
        driver.implicitly_wait(1)
        for radio_button in driver.find_elements_by_xpath('//*[@type="radio" and @value="0"]'):
            radio_button.click()
        if not debug:
            driver.find_element_by_id('apply').click()
        driver.implicitly_wait(1)
        print('Application Successful.')
    except (NoSuchElementException, ElementNotVisibleException):
        if not debug:
            driver.find_element_by_id('apply').click()
        driver.implicitly_wait(1)
        print('Application Successful.')
    finally:
        driver.switch_to.window(driver.window_handles[0])
项目:dbas    作者:hhucn    | 项目源码 | 文件源码
def test_wrapper(name, id, test_function, *args):
        """
        Wrapper method
        :param name: of the test
        :param id: of the test
        :param test_function: the function itself
        :return: value of the test_function on success, 0 otherwise
        """
        ret_val = 0
        try:
            global test_counter
            test_counter += 1
            ret_val = test_function(*args)
            print('    ' + str(id) + ': ' + ('SUCCESS' if ret_val == 1 else 'FAIL'))
            print('')
        except AttributeError as e:
            Helper.print_error('AttributeError', name, e)
        except exceptions.ElementDoesNotExist as e:
            Helper.print_error('ElementDoesNotExist', name, e)
        except IndexError as e:
            Helper.print_error('IndexError', name, e)
        except ElementNotVisibleException as e:
            Helper.print_error('ElementNotVisibleException', name, e)
        except WebDriverException as e:
            Helper.print_error('WebDriverException', name, e)
        except ConnectionResetError as e:
            Helper.print_error('ConnectionResetError', name, e)
        except ConnectionRefusedError as e:
            Helper.print_error('ConnectionRefusedError', name, e)
        except Exception as e:
            Helper.print_error('Exception', name, e)
        finally:
            return ret_val if ret_val != 0 else ret_val
项目:cyphon    作者:dunbarcyber    | 项目源码 | 文件源码
def test_can_remove_form(self):
        """
        Test for ability to remove a form from the formset.
        """
        url = 'http://localhost:8000/collections/mongodb/cyphon/posts/query'
        self.webdriver.get(url)

        add_filter = self.webdriver.find_element_by_id('id_add_filter')
        remove_filter = self.webdriver.find_element_by_id('id_remove_filter')
        joiner = self.webdriver.find_element_by_id('id_joiner')

        filters = self.webdriver.find_elements_by_css_selector('#id_formset .filter')
        self.assertEqual(len(filters), 1)

        num_forms = self.webdriver.find_element_by_id('id_form-TOTAL_FORMS')
        self.assertEqual(num_forms.get_attribute('value'), '1')

        with self.assertRaises(ElementNotVisibleException):
            remove_filter.click()

        with self.assertRaises(ElementNotVisibleException):
            joiner.click()

        add_filter.click()
        add_filter.click()

        filters = self.webdriver.find_elements_by_css_selector('#id_formset .filter')
        self.assertEqual(len(filters), 3)

        num_forms = self.webdriver.find_element_by_id('id_form-TOTAL_FORMS')
        self.assertEqual(num_forms.get_attribute('value'), '3')

        remove_filter.click()
        remove_filter.click()

        filters = self.webdriver.find_elements_by_css_selector('#id_formset .filter')
        self.assertEqual(len(filters), 1)

        num_forms = self.webdriver.find_element_by_id('id_form-TOTAL_FORMS')
        self.assertEqual(num_forms.get_attribute('value'), '1')

        with self.assertRaises(ElementNotVisibleException):
            remove_filter.click()

        with self.assertRaises(ElementNotVisibleException):
            joiner.click()
项目:test-automation    作者:openstax    | 项目源码 | 文件源码
def test_user_cancel_feedback_before_making_changes_58316(self):
        """Cancel feedback.

        Steps:
        Click "Get Help" from the user menu
        Enter a question or search words into the search engine
        Click "Search" or press enter
        Click on a search result
        Scroll to "Feedback"
        Click "No"
        [optional] Enter feedback into the text box
        Click "Cancel"

        Expected Result:
        The popup box closes
        """
        self.ps.test_updates['name'] = 't2.18.012' \
            + inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates['tags'] = ['t2', 't2.18', 't2.18.012', '58316']
        self.ps.test_updates['passed'] = False

        # Test steps and verification assertions
        self.teacher.login()
        self.teacher.find(By.XPATH, '//p[@data-is-beta="true"]').click()
        self.teacher.open_user_menu()
        self.teacher.find(By.LINK_TEXT, 'Get Help').click()
        self.teacher.sleep(1)

        window_with_help = self.teacher.driver.window_handles[1]
        self.teacher.driver.switch_to_window(window_with_help)
        self.teacher.find(By.ID, 'searchAskInput') \
            .send_keys('question')
        self.teacher.find(By.ID, 'searchAskButton').click()
        self.teacher.page.wait_for_page_load()

        self.teacher.find(By.CSS_SELECTOR, '.article a').click()
        assert('articles' in self.teacher.current_url()), 'not at the article'

        self.teacher.find(By.CSS_SELECTOR, '#feedback [value="No"]').click()
        self.teacher.wait.until(
            expect.visibility_of_element_located((
                By.ID,
                'feedbackDialog'
            ))
        )
        self.teacher.find(By.CSS_SELECTOR, '[value="Cancel"]').click()
        with self.assertRaises(ElementNotVisibleException):
            self.teacher.find(By.ID, 'feedbackDialog').click()

        self.ps.test_updates['passed'] = True

    # C58318 - 013 - User | View related articles
项目:recaptcha-cracker    作者:nocturnaltortoise    | 项目源码 | 文件源码
def start():
    captcha_cracker.setup()
    captcha_cracker.captcha_element.click_initial_checkbox()
    time.sleep(0.5)
    if captcha_cracker.captcha_correct():
        captcha_cracker.num_guesses += 1
        captcha_cracker.num_correct += 1

        captcha_cracker.print_stats()
        browser_reload()

    while captcha_cracker.num_guesses < MAX_RUNS:
        try:
            captcha_cracker.get_new_captcha()
            captcha_cracker.preprocess_images()
            captcha_cracker.get_predictions()
            # matching_checkboxes = captcha_cracker.select_random_checkboxes()
            # uncomment to run random clicker, 
            # comment get_predictions and select_correct_checkboxes as well if doing that
            matching_checkboxes = captcha_cracker.select_correct_checkboxes()
            time.sleep(1)
            # refresh the checkboxes as the urls may have changed, and we need to check the new urls
            captcha_cracker.refresh_checkboxes()

            if matching_checkboxes:
                if captcha_cracker.captcha_changed():
                    continue
                else:
                    captcha_cracker.verify()
                    captcha_cracker.num_guesses += 1
            else:
                if captcha_cracker.captcha_changed():
                    captcha_cracker.verify()
                else:
                    captcha_cracker.reload()
                captcha_cracker.num_guesses += 1

            time.sleep(0.5)
            captcha_correct = captcha_cracker.captcha_correct()
            if captcha_correct:
                captcha_cracker.num_correct += 1

            write_guesses_to_file(captcha_cracker.captcha_element.captcha, matching_checkboxes, captcha_correct)
            captcha_cracker.print_stats()

        except SameCaptchaException:
            browser_reload()
        except (ElementNotVisibleException,
                StaleElementReferenceException,
                CaptchaImageNotFoundException,
                CheckboxNotFoundException,
                InvalidElementStateException,
                QueryTextNotFoundException):
            browser_reload()