Python selenium.webdriver.common.by.By.PARTIAL_LINK_TEXT Examples

The following are 8 code examples of selenium.webdriver.common.by.By.PARTIAL_LINK_TEXT(). 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.common.by.By , or try the search function .
Example #1
Source File: pge.py    From finance-dl with GNU General Public License v2.0 6 votes vote down vote up
def get_bills(self, output_dir):
        logger.info('Looking for download link')
        (bills_link, ), = self.wait_and_return(
            lambda: self.find_visible_elements_by_descendant_partial_text('BILL & PAYMENT HISTORY', 'h2'))
        scrape_lib.retry(lambda: self.click(bills_link), retry_delay=2)
        links, = self.wait_and_return(
            lambda: self.find_visible_elements(By.PARTIAL_LINK_TEXT, "View Bill PDF")
        )

        def do_download(link):
            scrape_lib.retry(lambda: self.click(link), retry_delay=2)
            logger.info('Waiting for download')
            download_result, = self.wait_and_return(self.get_downloaded_file)
            return self.process_download(download_result, output_dir)

        for link in links:
            if not do_download(link):
                break 
Example #2
Source File: formgrade_utils.py    From nbgrader with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _click_link(browser, link_text, partial=False):
    if partial:
        WebDriverWait(browser, 10).until(
            EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, link_text)))
        element = browser.find_element_by_partial_link_text(link_text)
    else:
        WebDriverWait(browser, 10).until(
            EC.presence_of_element_located((By.LINK_TEXT, link_text)))
        element = browser.find_element_by_link_text(link_text)
    element.click() 
Example #3
Source File: stockplanconnect.py    From finance-dl with GNU General Public License v2.0 5 votes vote down vote up
def get_documents(self):
        logger.info('Looking for documents link')
        documents, = self.wait_and_locate((By.PARTIAL_LINK_TEXT, 'Documents'))
        scrape_lib.retry(lambda: self.click(documents), num_tries=3,
                         retry_delay=5)
        self.download_documents() 
Example #4
Source File: by.py    From selene with MIT License 5 votes vote down vote up
def partial_link_text(value):
    return By.PARTIAL_LINK_TEXT, value 
Example #5
Source File: bys.py    From selene with MIT License 5 votes vote down vote up
def by_partial_link_text(text):
    warnings.warn('deprecated; use by.* from selene.support.by', DeprecationWarning)
    return (By.PARTIAL_LINK_TEXT, text) 
Example #6
Source File: requestium.py    From requestium with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def ensure_element(self, locator, selector, state="present", timeout=None):
        """This method allows us to wait till an element appears or disappears in the browser

        The webdriver runs in parallel with our scripts, so we must wait for it everytime it
        runs javascript. Selenium automatically waits till a page loads when GETing it,
        but it doesn't do this when it runs javascript and makes AJAX requests.
        So we must explicitly wait in that case.

        The 'locator' argument defines what strategy we use to search for the element.

        The 'state' argument allows us to chose between waiting for the element to be visible,
        clickable, present, or invisible. Presence is more inclusive, but sometimes we want to
        know if the element is visible. Careful, its not always intuitive what Selenium considers
        to be a visible element. We can also wait for it to be clickable, although this method
        is a bit buggy in selenium, an element can be 'clickable' according to selenium and 
        still fail when we try to click it.

        More info at: http://selenium-python.readthedocs.io/waits.html
        """
        locators = {'id': By.ID,
                    'name': By.NAME,
                    'xpath': By.XPATH,
                    'link_text': By.LINK_TEXT,
                    'partial_link_text': By.PARTIAL_LINK_TEXT,
                    'tag_name': By.TAG_NAME,
                    'class_name': By.CLASS_NAME,
                    'css_selector': By.CSS_SELECTOR}
        locator = locators[locator]
        if not timeout: timeout = self.default_timeout

        if state == 'visible':
            element = WebDriverWait(self, timeout).until(
                EC.visibility_of_element_located((locator, selector))
            )
        elif state == 'clickable':
            element = WebDriverWait(self, timeout).until(
                EC.element_to_be_clickable((locator, selector))
            )
        elif state == 'present':
            element = WebDriverWait(self, timeout).until(
                EC.presence_of_element_located((locator, selector))
            )
        elif state == 'invisible':
            WebDriverWait(self, timeout).until(
                EC.invisibility_of_element_located((locator, selector))
            )
            element = None
        else:
            raise ValueError(
                "The 'state' argument must be 'visible', 'clickable', 'present' "
                "or 'invisible', not '{}'".format(state)
            )

        # We add this method to our element to provide a more robust click. Chromedriver
        # sometimes needs some time before it can click an item, specially if it needs to
        # scroll into it first. This method ensures clicks don't fail because of this.
        if element:
            element.ensure_click = partial(_ensure_click, element)
        return element 
Example #7
Source File: webdriver.py    From seldom with Apache License 2.0 4 votes vote down vote up
def get_element(**kwargs):
    """
    Judge element positioning way, and returns the element.
    """
    if not kwargs:
        raise ValueError("Please specify a locator")
    if len(kwargs) > 1:
        raise ValueError("Please specify only one locator")

    by, value = next(iter(kwargs.items()))
    try:
        LOCATOR_LIST[by]
    except KeyError:
        raise ValueError("Element positioning of type '{}' is not supported. ".format(by))

    if by == "id_":
        find_element((By.ID, value))
        elem = Seldom.driver.find_elements_by_id(value)
    elif by == "name":
        find_element((By.NAME, value))
        elem = Seldom.driver.find_elements_by_name(value)
    elif by == "class_name":
        find_element((By.CLASS_NAME, value))
        elem = Seldom.driver.find_elements_by_class_name(value)
    elif by == "tag":
        find_element((By.TAG_NAME, value))
        elem = Seldom.driver.find_elements_by_tag_name(value)
    elif by == "link_text":
        find_element((By.LINK_TEXT, value))
        elem = Seldom.driver.find_elements_by_link_text(value)
    elif by == "partial_link_text":
        find_element((By.PARTIAL_LINK_TEXT, value))
        elem = Seldom.driver.find_elements_by_partial_link_text(value)
    elif by == "xpath":
        find_element((By.XPATH, value))
        elem = Seldom.driver.find_elements_by_xpath(value)
    elif by == "css":
        find_element((By.CSS_SELECTOR, value))
        elem = Seldom.driver.find_elements_by_css_selector(value)
    else:
        raise NameError(
            "Please enter the correct targeting elements,'id_/name/class_name/tag/link_text/xpath/css'.")

    return elem 
Example #8
Source File: RobotAppEyes.py    From Robot-AppEyes with Apache License 2.0 4 votes vote down vote up
def check_eyes_region_by_selector(self, selector, value, name, includeEyesLog=False, httpDebugLog=False):
        """
        Takes a snapshot of the region of the element found by calling find_element(by, value) from the browser using the web driver
        and matches it with the expected output. With a choice from eight selectors, listed below to check by.

        Arguments:
                |  Selector (string)                | This will decide what element will be located. The supported selectors include: CSS SELECTOR, XPATH, ID, LINK TEXT, PARTIAL LINK TEXT, NAME, TAG NAME, CLASS NAME.    |
                |  Value (string)                   | The specific value of the selector. e.g. a CSS SELECTOR value .first.expanded.dropdown                                                                                |
                |  Name (string)                    | Name that will be given to region in Eyes.                                                                                                                            |
                |  Include Eyes Log (default=False) | The Eyes logs will not be included by default. To activate, pass 'True' in the variable.                                                                              |
                |  HTTP Debug Log (default=False)   | The HTTP Debug logs will not be included by default. To activate, pass 'True' in the variable.                                                                        |
        Example:

        | *Keywords*                    |  *Parameters*                                                                                                            |
        | Open Browser                  |  http://www.navinet.net/  |  gc                       |                            |                    |        |       |
        | Open Eyes Session             |  http://www.navinet.net/  |  RobotAppEyes_Test        |  NaviNet_RobotAppEyes_Test |  YourApplitoolsKey |  1024  |  768  |
        | Check Eyes Region By Selector |  CSS SELECTOR             |  .first.expanded.dropdown |  NaviNetCssElement         |                    |        |       |
        | Close Eyes Session            |  False                    |                           |                            |                    |        |       |

        """
        if includeEyesLog is True:
            logger.set_logger(StdoutLogger())
            logger.open_()
        if httpDebugLog is True:
            httplib.HTTPConnection.debuglevel = 1

        searchElement = None

        if selector.upper() == 'CSS SELECTOR':
            searchElement = By.CSS_SELECTOR
        elif selector.upper() == 'XPATH':
            searchElement = By.XPATH
        elif selector.upper() == 'ID':
            searchElement = By.ID
        elif selector.upper() == 'LINK TEXT':
            searchElement = By.LINK_TEXT
        elif selector.upper() == 'PARTIAL LINK TEXT':
            searchElement = By.PARTIAL_LINK_TEXT
        elif selector.upper() == 'NAME':
            searchElement = By.NAME
        elif selector.upper() == 'TAG NAME':
            searchElement = By.TAG_NAME
        elif selector.upper() == 'CLASS NAME':
            searchElement = By.CLASS_NAME
        else:
            raise InvalidElementStateException('Please select a valid selector: CSS SELECTOR, XPATH, ID, LINK TEXT, PARTIAL LINK TEXT, NAME, TAG NAME, CLASS NAME')

        eyes.check_region_by_selector(searchElement, value, name)