当前位置: 首页>>代码示例>>Python>>正文


Python exceptions.ElementNotVisibleException方法代码示例

本文整理汇总了Python中selenium.common.exceptions.ElementNotVisibleException方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.ElementNotVisibleException方法的具体用法?Python exceptions.ElementNotVisibleException怎么用?Python exceptions.ElementNotVisibleException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在selenium.common.exceptions的用法示例。


在下文中一共展示了exceptions.ElementNotVisibleException方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: confirm_unfriend

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import ElementNotVisibleException [as 别名]
def confirm_unfriend(browser):
    """ Deal with the confirmation dialog boxes during an unfollow """
    attempt = 0

    while attempt < 3:
        try:
            attempt += 1
            button_xp = "//button[text()='Unfollow']"  # "//button[contains(
            # text(), 'Unfollow')]"
            unfollow_button = browser.find_element_by_xpath(button_xp)

            if unfollow_button.is_displayed():
                click_element(browser, Settings, unfollow_button)
                sleep(2)
                break

        except (ElementNotVisibleException, NoSuchElementException) as exc:
            # prob confirm dialog didn't pop up
            if isinstance(exc, ElementNotVisibleException):
                break

            elif isinstance(exc, NoSuchElementException):
                sleep(1) 
开发者ID:ishandutta2007,项目名称:FacebookPy,代码行数:25,代码来源:unfriend_util.py

示例2: confirm_unfollow

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import ElementNotVisibleException [as 别名]
def confirm_unfollow(browser):
    """ Deal with the confirmation dialog boxes during an unfollow """
    attempt = 0

    while attempt < 3:
        try:
            attempt += 1
            button_xp = "//button[text()='Unfollow']"  # "//button[contains(
            # text(), 'Unfollow')]"
            unfollow_button = browser.find_element_by_xpath(button_xp)

            if unfollow_button.is_displayed():
                click_element(browser, Settings, unfollow_button)
                sleep(2)
                break

        except (ElementNotVisibleException, NoSuchElementException) as exc:
            # prob confirm dialog didn't pop up
            if isinstance(exc, ElementNotVisibleException):
                break

            elif isinstance(exc, NoSuchElementException):
                sleep(1) 
开发者ID:ishandutta2007,项目名称:FacebookPy,代码行数:25,代码来源:unfollow_util.py

示例3: confirm_unfollow

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import ElementNotVisibleException [as 别名]
def confirm_unfollow(browser):
    """ Deal with the confirmation dialog boxes during an unfollow """
    attempt = 0

    while attempt < 3:
        try:
            attempt += 1
            button_xp = read_xpath(
                confirm_unfollow.__name__, "button_xp"
            )  # "//button[contains(
            # text(), 'Unfollow')]"
            unfollow_button = browser.find_element_by_xpath(button_xp)

            if unfollow_button.is_displayed():
                click_element(browser, unfollow_button)
                sleep(2)
                break

        except (ElementNotVisibleException, NoSuchElementException) as exc:
            # prob confirm dialog didn't pop up
            if isinstance(exc, ElementNotVisibleException):
                break

            elif isinstance(exc, NoSuchElementException):
                sleep(1) 
开发者ID:Instagram-Tools,项目名称:bot,代码行数:27,代码来源:unfollow_util.py

示例4: send_picture

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import ElementNotVisibleException [as 别名]
def send_picture(self, name, picture_location, caption=None):
        search = self.browser.find_element_by_css_selector("._3FRCZ")
        search.send_keys(name+Keys.ENTER)  # we will send the name to the input key box
        try:
            attach_xpath = '//*[@id="main"]/header/div[3]/div/div[2]/div'
            send_file_xpath = '/html/body/div[1]/div/div/div[2]/div[2]/span/div/span/div/div/div[2]/span/div/div/span'
            attach_type_xpath = '/html/body/div[1]/div/div/div[4]/div/header/div[3]/div/div[2]/span/div/div/ul/li[1]/button/input'
            # open attach menu
            attach_btn = self.browser.find_element_by_xpath(attach_xpath)
            attach_btn.click()

            # Find attach file btn and send screenshot path to input
            time.sleep(1)
            attach_img_btn = self.browser.find_element_by_xpath(attach_type_xpath)

            # TODO - might need to click on transportation mode if url doesn't work
            attach_img_btn.send_keys(picture_location)           # get current script path + img_path
            time.sleep(1)
            if caption:
                caption_xpath = "/html/body/div[1]/div/div/div[2]/div[2]/span/div/span/div/div/div[2]/div/span/div/div[2]/div/div[3]/div[1]/div[2]"
                send_caption = self.browser.find_element_by_xpath(caption_xpath)
                send_caption.send_keys(caption)
            send_btn = self.browser.find_element_by_xpath(send_file_xpath)
            send_btn.click()

        except (NoSuchElementException, ElementNotVisibleException) as e:
            print(str(e))

    # For sending documents 
开发者ID:VISWESWARAN1998,项目名称:Simple-Yet-Hackable-WhatsApp-api,代码行数:31,代码来源:whatsapp.py

示例5: send_document

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import ElementNotVisibleException [as 别名]
def send_document(self, name, document_location):
        search = self.browser.find_element_by_css_selector("._3FRCZ")
        search.send_keys(name+Keys.ENTER)  # we will send the name to the input key box
        try:
            attach_xpath = '//*[@id="main"]/header/div[3]/div/div[2]/div'
            send_file_xpath = '/html/body/div[1]/div/div/div[2]/div[2]/span/div/span/div/div/div[2]/span/div/div/span'
            attach_type_xpath = '/html/body/div[1]/div/div/div[4]/div/header/div[3]/div/div[2]/span/div/div/ul/li[3]/button/input'
            # open attach menu
            attach_btn = self.browser.find_element_by_xpath(attach_xpath)
            attach_btn.click()

            # Find attach file btn and send screenshot path to input
            time.sleep(1)
            attach_img_btn = self.browser.find_element_by_xpath(attach_type_xpath)

            # TODO - might need to click on transportation mode if url doesn't work
            attach_img_btn.send_keys(document_location)           # get current script path + img_path
            time.sleep(1)
            send_btn = self.browser.find_element_by_xpath(send_file_xpath)
            send_btn.click()

        except (NoSuchElementException, ElementNotVisibleException) as e:
            print(str(e))



    # Clear the chat 
开发者ID:VISWESWARAN1998,项目名称:Simple-Yet-Hackable-WhatsApp-api,代码行数:29,代码来源:whatsapp.py

示例6: set_group_picture

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import ElementNotVisibleException [as 别名]
def set_group_picture(self, group_name, picture_location):
        search = self.browser.find_element_by_css_selector("._3FRCZ")
        search.send_keys(group_name+Keys.ENTER)  # we will send the group name to the input key box
        try:
            menu_xpath = '/html/body/div[1]/div/div/div[4]/div/header/div[3]/div/div[3]/div/span'
            group_info_xpath = '/html/body/div[1]/div/div/div[4]/div/header/div[3]/div/div[3]/span/div/ul/li[1]/div'
            image_input_xpath = '/html/body/div[1]/div/div/div[2]/div[3]/span/div/span/div/div/div[1]/div[1]/div[1]/div/input'
            zoom_out_xpath = '/html/body/div[1]/div/span[2]/div/div/div/div/div/div/span/div/div/div[1]/div[1]/div[2]/span'
            save_btn_xpath = '/html/body/div[1]/div/span[2]/div/div/div/div/div/div/span/div/div/div[2]/span/div/div'
            exit_group_info_xpath = '/html/body/div[1]/div/div/div[2]/div[3]/span/div/span/div/header/div/div[1]/button/span'

            # open group info
            menu = self.browser.find_element_by_xpath(menu_xpath)
            menu.click()
            time.sleep(1)
            group_info = self.browser.find_element_by_xpath(group_info_xpath)
            group_info.click()

            # find image input and send picutre path
            time.sleep(1)
            image_input = self.browser.find_element_by_xpath(image_input_xpath)
            image_input.send_keys(picture_location)

            # zoom out picture and save
            time.sleep(1)
            zoom_out = self.browser.find_element_by_xpath(zoom_out_xpath)
            for i in range(0, 5):
                zoom_out.click()
            save_btn = self.browser.find_element_by_xpath(save_btn_xpath)
            save_btn.click()

            # close the group info
            time.sleep(1)
            exit_group_info = self.browser.find_element_by_xpath(exit_group_info_xpath)
            exit_group_info.click()
        except (NoSuchElementException, ElementNotVisibleException) as e:
            print(str(e)) 
开发者ID:VISWESWARAN1998,项目名称:Simple-Yet-Hackable-WhatsApp-api,代码行数:39,代码来源:whatsapp.py

示例7: _attach_and_send_screenshot

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import ElementNotVisibleException [as 别名]
def _attach_and_send_screenshot(self):
        # TODO - ElementNotVisibleException - this shouldn't happen but when would it

        # local variables for x_path elements on browser
        attach_xpath = '//*[@id="main"]/header/div[3]/div/div[2]/div'
        send_file_xpath = '/html/body/div[1]/div/div/div[2]/div[2]/span/div/span/div/div/div[2]/span[2]/div/div/span'

        if self.attachment_type == "img":
            attach_type_xpath = '/html/body/div[1]/div/div/div[4]/div/header/div[3]/div/div[2]/span/div/div/ul/li[1]/button/input'
        elif self.attachment_type == "cam":
            attach_type_xpath = '//*[@id="main"]/header/div[3]/div/div[2]/span/div/div/ul/li[2]/button'
        elif self.attachment_type == "doc":
            attach_type_xpath = '//*[@id="main"]/header/div[3]/div/div[2]/span/div/div/ul/li[3]/input'

        try:
            # open attach menu
            attach_btn = driver.find_element_by_xpath(attach_xpath)
            attach_btn.click()

            # Find attach file btn and send screenshot path to input
            time.sleep(1)
            attach_img_btn = driver.find_element_by_xpath(attach_type_xpath)

            # TODO - might need to click on transportation mode if url doesn't work
            attach_img_btn.send_keys(os.getcwd() + "/screenshot.png")           # get current script path + img_path
            time.sleep(1)
            send_btn = driver.find_element_by_xpath(send_file_xpath)
            send_btn.click()

        except (NoSuchElementException, ElementNotVisibleException) as e:
            print(str(e))
            send_message((str(e)))
            send_message("Bot failed to retrieve search content, try again...") 
开发者ID:jctissier,项目名称:whatsapp-assistant-bot,代码行数:35,代码来源:whatsapp_assistant_bot.py

示例8: _is_element_visible

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import ElementNotVisibleException [as 别名]
def _is_element_visible(self, *locator):
        try:
            return self._get_element(*locator).is_displayed()
        except (Exceptions.NoSuchElementException,
                Exceptions.ElementNotVisibleException):
            return False 
开发者ID:CiscoSystems,项目名称:avos,代码行数:8,代码来源:basewebobject.py

示例9: start

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import ElementNotVisibleException [as 别名]
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() 
开发者ID:nocturnaltortoise,项目名称:recaptcha-cracker,代码行数:56,代码来源:captcha_input.py

示例10: scrape_page

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import ElementNotVisibleException [as 别名]
def scrape_page(url):
    """

    :param url: Game pbp url

    :return n pages - each have period info
    """
    driver = webdriver.Firefox()
    wait = WebDriverWait(driver, 10)

    driver.get(url)
    time.sleep(8)

    """

    for _ in range(5):
        driver.execute_script("window.scrollTo(0,document.body.scrollHeight)")
        time.sleep(.2)
    #['SO', 'OT', 'OT1', 'OT2', '3', '2', '1']:


    for period in ['3', '2', '1']: 
        btn = '//a[@ng-click="ctrl.period = \'{}\'"]'.format(period)

        try:
            wait.until(EC.element_to_be_clickable((By.XPATH, btn)))
            #driver.find_element_by_xpath(btn).click()
            btn_elem = driver.find_element_by_xpath(btn)
            ActionChains(driver).move_to_element(btn_elem).click().perform()
        except (TimeoutException, ElementNotVisibleException, WebDriverException) as e:
            print(e)

        ### This just print the last row in the list to see if we are correctly toggling between periods
        soup = BeautifulSoup(driver.page_source, "lxml")
        plays_table = soup.find("table", {"class": "play-by-play"})
        plays = plays_table.find_all("tr")
        print(plays[-1])

    """

    pg = driver.page_source
    driver.close()

    return pg 
开发者ID:HarryShomer,项目名称:Hockey-Scraper,代码行数:46,代码来源:game_pbp.py

示例11: google

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import ElementNotVisibleException [as 别名]
def google(self, keyword, add_url=""):
        self.browser.get("https://www.google.com/search?q={}&source=lnms&tbm=isch{}".format(keyword, add_url))

        time.sleep(1)

        print('Scrolling down')

        elem = self.browser.find_element_by_tag_name("body")

        for i in range(60):
            elem.send_keys(Keys.PAGE_DOWN)
            time.sleep(0.2)

        try:
            # You may need to change this. Because google image changes rapidly.
            # btn_more = self.browser.find_element(By.XPATH, '//input[@value="결과 더보기"]')
            # self.wait_and_click('//input[@id="smb"]')
            self.wait_and_click('//input[@type="button"]')

            for i in range(60):
                elem.send_keys(Keys.PAGE_DOWN)
                time.sleep(0.2)

        except ElementNotVisibleException:
            pass

        photo_grid_boxes = self.browser.find_elements(By.XPATH, '//div[@class="bRMDJf islir"]')

        print('Scraping links')

        links = []

        for box in photo_grid_boxes:
            try:
                imgs = box.find_elements(By.TAG_NAME, 'img')

                for img in imgs:
                    # self.highlight(img)
                    src = img.get_attribute("src")

                    # Google seems to preload 20 images as base64
                    if str(src).startswith('data:'):
                        src = img.get_attribute("data-iurl")
                    links.append(src)

            except Exception as e:
                print('[Exception occurred while collecting links from google] {}'.format(e))

        links = self.remove_duplicates(links)

        print('Collect links done. Site: {}, Keyword: {}, Total: {}'.format('google', keyword, len(links)))
        self.browser.close()

        return links 
开发者ID:YoongiKim,项目名称:AutoCrawler,代码行数:56,代码来源:collect_links.py

示例12: naver

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import ElementNotVisibleException [as 别名]
def naver(self, keyword, add_url=""):
        self.browser.get("https://search.naver.com/search.naver?where=image&sm=tab_jum&query={}{}".format(keyword, add_url))

        time.sleep(1)

        print('Scrolling down')

        elem = self.browser.find_element_by_tag_name("body")

        for i in range(60):
            elem.send_keys(Keys.PAGE_DOWN)
            time.sleep(0.2)

        try:
            self.wait_and_click('//a[@class="btn_more _more"]')

            for i in range(60):
                elem.send_keys(Keys.PAGE_DOWN)
                time.sleep(0.2)

        except ElementNotVisibleException:
            pass

        photo_grid_boxes = self.browser.find_elements(By.XPATH, '//div[@class="photo_grid _box"]')

        print('Scraping links')

        links = []

        for box in photo_grid_boxes:
            try:
                imgs = box.find_elements(By.CLASS_NAME, '_img')

                for img in imgs:
                    # self.highlight(img)
                    src = img.get_attribute("src")
                    if src[0] != 'd':
                        links.append(src)
            except Exception as e:
                print('[Exception occurred while collecting links from naver] {}'.format(e))

        links = self.remove_duplicates(links)

        print('Collect links done. Site: {}, Keyword: {}, Total: {}'.format('naver', keyword, len(links)))
        self.browser.close()

        return links 
开发者ID:YoongiKim,项目名称:AutoCrawler,代码行数:49,代码来源:collect_links.py

示例13: test_learners_states

# 需要导入模块: from selenium.common import exceptions [as 别名]
# 或者: from selenium.common.exceptions import ElementNotVisibleException [as 别名]
def test_learners_states(browser, override_allowed_hosts, seeded_database_loader, django_db_blocker, test_data):
    """Iterate through all possible dashboard states and save screenshots/API results of each one"""
    output_directory = DASHBOARD_STATES_OPTIONS.get('output_directory')
    os.makedirs(output_directory, exist_ok=True)
    use_mobile = DASHBOARD_STATES_OPTIONS.get('mobile')
    if use_mobile:
        browser.driver.set_window_size(480, 854)

    learners_states = LearnersStates(test_data['user'])
    learners_state_iter = enumerate(learners_states)
    match = DASHBOARD_STATES_OPTIONS.get('match')
    if match is not None:
        learners_state_iter = filter(
            lambda scenario: match in make_filename(scenario[0], scenario[1][1]),
            learners_state_iter
        )

    LoginPage(browser).log_in_via_admin(learners_states.user, DEFAULT_PASSWORD)
    recreate_index()

    # warm the cache
    browser.get("/learners")

    for num, (run_scenario, name) in learners_state_iter:
        skip_screenshot = False
        with django_db_blocker.unblock():
            learners_states.user.refresh_from_db()
            filename = make_filename(num, name, output_directory=output_directory, use_mobile=use_mobile)
            new_url = run_scenario()
            if not skip_screenshot:
                browser.get(new_url)
                browser.wait_until_loaded(By.CSS_SELECTOR, '.sk-hits,.no-hits')
                browser.wait_until_loaded(By.CLASS_NAME, 'micromasters-title')
                try:
                    browser.click_when_loaded(
                        By.CSS_SELECTOR,
                        '.filter--company_name .Select-arrow-zone',
                        retries=0,
                    )
                except ElementNotVisibleException:
                    # We are trying to make the work history visible, but if it doesn't exist
                    # there's nothing to do
                    pass
                # sometimes the browser scrolls down for some reason after clicking
                browser.driver.execute_script("window.scrollTo(0, 0)")
                browser.take_screenshot(filename=filename)
        with django_db_blocker.unblock():
            terminate_db_connections()
        seeded_database_loader.load_backup() 
开发者ID:mitodl,项目名称:micromasters,代码行数:51,代码来源:snapshot_learners_states.py


注:本文中的selenium.common.exceptions.ElementNotVisibleException方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。