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

The following are 30 code examples of selenium.webdriver.common.by.By.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: __init__.py    From ontask_b with MIT License 6 votes vote down vote up
def go_to_upload_merge(self):
        # Click in the top menu
        self.selenium.find_element_by_id('ontask-base-table').click()
        # Wait for the Full View to be clickable
        WebDriverWait(self.selenium, 10).until(
            EC.element_to_be_clickable(
                (By.LINK_TEXT, 'Upload or merge data')
            )
        )
        # Click on the upload and wait...
        self.selenium.find_element_by_link_text('Upload or merge data').click()
        WebDriverWait(self.selenium, 10).until(
            EC.visibility_of_element_located(
                (By.XPATH, '//table[@id="dataops-table"]')
            )
        ) 
Example #2
Source File: test_selenium.py    From ckanext-privatedatasets with GNU Affero General Public License v3.0 6 votes vote down vote up
def test_invalid_fields(self, allowed_users, acquire_url, expected_msg):

        # Create a default user
        user = 'user1'
        self.default_register(user)

        # Create the dataset
        self.login(user)
        pkg_name = 'Dataset 2'

        # Go the page to create the dataset
        driver = self.driver
        driver.get(self.base_url)
        WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, 'Datasets'))).click()
        WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, 'Add Dataset'))).click()

        # Fill the requested information
        self.fill_ds_general_info(pkg_name, 'Example description', ['tag1'], True, True, allowed_users, acquire_url)

        # Check the error message
        msg_error = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.XPATH, '//div[@id=\'content\']/div[3]/div/section/div/form/div/ul/li'))).text
        self.assertEqual(expected_msg, msg_error) 
Example #3
Source File: test_selenium.py    From ckanext-privatedatasets with GNU Affero General Public License v3.0 6 votes vote down vote up
def check_acquired(self, dataset, dataset_url, acquired, private):
        driver = self.driver
        driver.get(self.base_url + 'dashboard')
        WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, 'Acquired Datasets'))).click()

        if acquired and private:
            # This message could not be shown when the user has acquired at least one dataset
            self.assertEqual(None, re.search('You haven\'t acquired any datasets.', driver.page_source))
            # Access the dataset
            driver.find_element_by_link_text(dataset).click()
            self.assertEqual(self.base_url + 'dataset/%s' % dataset_url, driver.current_url)
        else:
            # If the user has not acquired the dataset, a link to this dataset could not be in the acquired dataset list
            self.assertEqual(None, re.search(dataset_url, driver.page_source))
            # When a user has not acquired any dataset, a message will be shown to inform the user
            self.assertNotEquals(None, re.search('You haven\'t acquired any datasets.', driver.page_source)) 
Example #4
Source File: nonstop_scenarios.py    From everware with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def scenario_simple(user):
    driver = commons.login(user)
    user.wait_for_element_present(By.ID, "start")
    driver.find_element_by_id("start").click()
    commons.fill_repo_info(driver, user, user.repo)
    user.log("spawn clicked")
    user.wait_for_element_present(By.LINK_TEXT, "Control Panel")
    old_files = get_files(driver)
    driver.find_element_by_link_text("Control Panel").click()
    user.wait_for_element_present(By.ID, "stop")
    driver.find_element_by_id("stop").click()
    user.log("stop clicked")
    user.wait_for_pattern_in_page(r"Launch\s+a\s+notebook")

    driver.find_element_by_id("start").click()
    commons.fill_repo_info(driver, user, 'https://github.com/everware/travis-test-repo')
    user.log("spawn clicked (second time)")
    user.wait_for_element_present(By.LINK_TEXT, "Control Panel")
    new_files = get_files(driver)

    assert old_files != new_files, """It's an old container:
    Old elems: %s, New elems: %s
    """ % (' '.join(old_files), ' '.join(new_files)) 
Example #5
Source File: test_selenium.py    From ckanext-privatedatasets with GNU Affero General Public License v3.0 6 votes vote down vote up
def create_organization(self, name, description, users):
        driver = self.driver
        driver.get(self.base_url)
        WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, 'Organizations'))).click()
        WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, 'Add Organization'))).click()
        WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, 'field-name')))

        # Wait a bit to let ckan add javascript hooks
        time.sleep(0.2)

        driver.find_element_by_id('field-name').clear()
        driver.find_element_by_id('field-name').send_keys(name)
        driver.find_element_by_id('field-description').clear()
        driver.find_element_by_id('field-description').send_keys(description)
        driver.find_element_by_name('save').click()

        # Add users
        WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, 'Manage'))).click()
        WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, 'Members'))).click()
        for user in users:
            WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, 'Add Member'))).click()
            WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, "s2id_autogen1"))).send_keys(user + Keys.RETURN)
            driver.find_element_by_name('submit').click() 
Example #6
Source File: test_selenium.py    From ckanext-datarequests with GNU Affero General Public License v3.0 6 votes vote down vote up
def check_datarequest(self, datarequest_id, title, description, open, owner, 
                          organization='None', accepted_dataset='None'):
        driver = self.driver
        driver.get(self.base_url + 'datarequest/' + datarequest_id)

        self.assertEqual(title, driver.find_element_by_css_selector('h1.page-heading').text)
        self.assertEqual(description, driver.find_element_by_css_selector('p').text)

        self.assertEqual('OPEN' if open else 'CLOSED',
                         driver.find_element_by_xpath('//div[@id=\'content\']/div[3]/div/article/div/span').text)

        if open:
            self.assertEqual(owner, self.is_element_present(By.LINK_TEXT, 'Close'))

        self.assertEqual(organization, driver.find_element_by_xpath(
                         '//div[@id=\'content\']/div[3]/div/article/div/section/table/tbody/tr[2]/td').text)

        if not open:
            self.assertEqual(accepted_dataset, driver.find_element_by_xpath(
                             '//div[@id=\'content\']/div[3]/div/article/div/section/table/tbody/tr[5]/td').text)

        self.assertEqual(owner, self.is_element_present(By.LINK_TEXT, 'Manage')) 
Example #7
Source File: normal_scenarios.py    From everware with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def scenario_no_jupyter(user):
    driver = commons.login(user)
    user.wait_for_element_present(By.ID, "start")
    driver.find_element_by_id("start").click()
    commons.fill_repo_info(driver, user, 'docker:busybox')
    user.log("spawn clicked")
    user.wait_for_element_present(By.ID, "resist")
    user.log("correct, no jupyter in container")
    driver.find_element_by_id("resist").click()
    commons.fill_repo_info(driver, user, user.repo)
    user.log("spawn clicked (second try)")
    user.wait_for_element_present(By.LINK_TEXT, "Control Panel")
    driver.find_element_by_link_text("Control Panel").click()
    user.wait_for_element_present(By.ID, "stop")
    driver.find_element_by_id("stop").click()
    user.log("stop clicked")
    user.wait_for_pattern_in_page(r"Launch\s+a\s+notebook")
    driver.find_element_by_id("logout").click()
    user.log("logout clicked") 
Example #8
Source File: __init__.py    From ontask_b with MIT License 6 votes vote down vote up
def go_to_table(self):
        # Click in the top menu
        self.selenium.find_element_by_id('ontask-base-table').click()
        # Wait for the Full View to be clickable
        WebDriverWait(self.selenium, 10).until(
            EC.element_to_be_clickable(
                (By.LINK_TEXT, 'Full view')
            )
        )
        # Click on the full view element
        self.selenium.find_element_by_link_text('Full view').click()
        # Wait for page to refresh
        WebDriverWait(self.selenium, 10).until(
            EC.presence_of_element_located((By.ID, 'table-content'))
        )
        WebDriverWait(self.selenium, 10).until_not(
            EC.visibility_of_element_located((By.ID, 'div-spinner'))
        )
        element = self.selenium.find_element_by_id('table-data')
        if element:
            # The table is present!
            self.wait_for_datatable('table-data_previous')

        self.assertIn('CSV Download', self.selenium.page_source) 
Example #9
Source File: bys.py    From selene with MIT License 5 votes vote down vote up
def by_link_text(text):
    warnings.warn('deprecated; use by.* from selene.support.by', DeprecationWarning)
    return (By.LINK_TEXT, text) 
Example #10
Source File: normal_scenarios.py    From everware with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def scenario_default_dockerfile(user):
    driver = commons.login(user)
    user.wait_for_element_present(By.ID, "start")
    driver.find_element_by_id("start").click()
    commons.fill_repo_info(driver, user, 'https://github.com/everware/runnable_examples')
    user.log("spawn clicked")
    user.wait_for_element_present(By.LINK_TEXT, "Control Panel")
    driver.find_element_by_link_text("Control Panel").click()
    user.wait_for_element_present(By.ID, "stop")
    driver.find_element_by_id("stop").click()
    user.log("stop clicked")
    user.wait_for_pattern_in_page(r"Launch\s+a\s+notebook")
    driver.find_element_by_id("logout").click()
    user.log("logout clicked") 
Example #11
Source File: normal_scenarios.py    From everware with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def scenario_default_private_repos(user):
    driver = commons.login(user, "a516f02935686c8e782" + "e958e6a627dc3a3b17baa") # seems, github deletes public tokens
    user.wait_for_element_present(By.ID, "start")
    driver.find_element_by_id("start").click()
    commons.fill_repo_info(driver, user, "https://github.com/yandexdataschool/everware_private_test")
    user.log("spawn clicked")
    user.wait_for_element_present(By.LINK_TEXT, "Control Panel")
    driver.find_element_by_link_text("Control Panel").click()
    user.wait_for_element_present(By.ID, "stop")
    driver.find_element_by_id("stop").click()
    user.log("stop clicked")
    user.wait_for_pattern_in_page(r"Launch\s+a\s+notebook")
    driver.find_element_by_id("logout").click()
    user.log("logout clicked") 
Example #12
Source File: test_selenium.py    From ckanext-oauth2 with GNU Affero General Public License v3.0 5 votes vote down vote up
def _log_in(self, referer, username=FILAB2_MAIL, password=FILAB_PASSWORD, authorize=True):
        driver = self.driver
        driver.get(referer)
        WebDriverWait(driver, 30).until(lambda driver: driver.current_url == referer)

        WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.LINK_TEXT, "Log in"))).click()
        self._introduce_log_in_parameters(username, password)

        if driver.current_url.startswith(IDM_URL) and authorize:
            WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.XPATH, "//button[@type='submit']"))).click() 
Example #13
Source File: normal_scenarios.py    From everware with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def scenario_full(user):
    driver = commons.login(user)
    user.wait_for_element_present(By.ID, "start")
    driver.find_element_by_id("start").click()
    commons.fill_repo_info(driver, user, user.repo)
    user.log("spawn clicked")
    user.wait_for_element_present(By.LINK_TEXT, "Control Panel")
    driver.find_element_by_link_text("Control Panel").click()
    user.wait_for_element_present(By.ID, "stop")
    driver.find_element_by_id("stop").click()
    user.log("stop clicked")
    user.wait_for_pattern_in_page(r"Launch\s+a\s+notebook")
    driver.find_element_by_id("logout").click()
    user.log("logout clicked") 
Example #14
Source File: test_selenium.py    From ckanext-oauth2 with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_register_btn(self):
        driver = self.driver
        driver.get(self.base_url)
        WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, "Register"))).click()
        WebDriverWait(driver, 10).until(lambda driver: driver.current_url == (IDM_URL + "/sign_up")) 
Example #15
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 #16
Source File: ebmud.py    From finance-dl with GNU General Public License v2.0 5 votes vote down vote up
def get_statements(self):
        logger.info('Looking for statement link')
        statements_link, = self.wait_and_locate((By.LINK_TEXT,
                                                 'View Statements'))
        statements_link.click()

        (statements_table, ), = self.wait_and_return(
            lambda: self.find_visible_elements_by_descendant_partial_text('Statement Date', 'table')
        )
        rows = statements_table.find_elements_by_xpath('tbody/tr/td')
        for row in rows:
            row_text_parts = row.text.split()
            assert len(row_text_parts) == 4
            statement_date = dateutil.parser.parse(row_text_parts[0]).date()
            output_date_format = '%Y-%m-%d'
            statement_path = os.path.join(
                self.output_directory, '%s.bill.pdf' %
                (statement_date.strftime(output_date_format), ))
            if os.path.exists(statement_path):
                logger.info('Skipping existing statement: %s', statement_path)
                continue
            logger.info('Downloading %s', statement_path)
            self.click(row)
            download_result, = self.wait_and_return(self.get_downloaded_file)
            tmp_path = statement_path + '.tmp'
            with open(tmp_path, 'wb') as f:
                f.write(download_result[1])
            os.rename(tmp_path, statement_path)
            logger.info('Wrote %s', statement_path) 
Example #17
Source File: by.py    From selene with MIT License 5 votes vote down vote up
def link_text(value):
    return By.LINK_TEXT, value 
Example #18
Source File: test_selenium.py    From ckanext-privatedatasets with GNU Affero General Public License v3.0 5 votes vote down vote up
def create_ds(self, name, description, tags, private, searchable, allowed_users, acquire_url, resource_url, resource_name, resource_description, resource_format):
        driver = self.driver
        driver.get(self.base_url)
        WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, 'Datasets'))).click()
        WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, 'Add Dataset'))).click()
        self.fill_ds_general_info(name, description, tags, private, searchable, allowed_users, acquire_url)

        # SECOND PAGE: Add Resources
        WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, "field-name")))

        # Wait a bit to let ckan add javascript hooks
        time.sleep(0.2)

        try:
            # The link button is only clicked if it's present
            driver.find_element_by_link_text('Link').click()
        except Exception:  # pragma: no cover
            pass

        driver.find_element_by_id('field-image-url').clear()
        driver.find_element_by_id('field-image-url').send_keys(resource_url)
        driver.find_element_by_id('field-name').clear()
        driver.find_element_by_id('field-name').send_keys(resource_name)
        driver.find_element_by_id('field-description').clear()
        driver.find_element_by_id('field-description').send_keys(resource_description)
        driver.find_element_by_id('s2id_autogen1').send_keys(resource_format + Keys.RETURN)
        driver.find_element_by_css_selector('button.btn.btn-primary').click() 
Example #19
Source File: test_selenium.py    From ckanext-privatedatasets with GNU Affero General Public License v3.0 5 votes vote down vote up
def login(self, username):
        driver = self.driver
        driver.get(self.base_url)
        login_btn = WebDriverWait(driver, 15).until(
            EC.element_to_be_clickable((By.LINK_TEXT, 'Log in'))
        )
        login_btn.click()

        WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, "field-login"))).clear()
        driver.find_element_by_id('field-login').send_keys(username)
        driver.find_element_by_id('field-password').clear()
        driver.find_element_by_id('field-password').send_keys("1234" + username)
        driver.find_element_by_id('field-remember').click()
        driver.find_element_by_css_selector('button.btn.btn-primary').click() 
Example #20
Source File: __init__.py    From ontask_b with MIT License 5 votes vote down vote up
def go_to_model(self):
        # Click in the top menu
        self.selenium.find_element_by_id('ontask-base-table').click()
        # Wait for the Full View to be clickable
        WebDriverWait(self.selenium, 10).until(
            EC.element_to_be_clickable(
                (By.LINK_TEXT, 'Run Model')
            )
        )
        # Click on the upload and wait...
        self.selenium.find_element_by_link_text('Run Model').click()
        self.wait_for_datatable('transform-table_previous') 
Example #21
Source File: __init__.py    From ontask_b with MIT License 5 votes vote down vote up
def go_to_transform(self):
        # Click in the top menu
        self.selenium.find_element_by_id('ontask-base-table').click()
        # Wait for the Full View to be clickable
        WebDriverWait(self.selenium, 10).until(
            EC.element_to_be_clickable(
                (By.LINK_TEXT, 'Run Transformation')
            )
        )
        # Click on the upload and wait...
        self.selenium.find_element_by_link_text('Run Transformation').click()
        self.wait_for_datatable('transform-table_previous') 
Example #22
Source File: webdriver.py    From seldom with Apache License 2.0 5 votes vote down vote up
def click_text(self, text):
        """
        Click the element by the link text

        Usage:
        self.click_text("新闻")
        """
        find_element((By.LINK_TEXT, text))
        Seldom.driver.find_element_by_link_text(text).click() 
Example #23
Source File: run_server_tests.py    From anvio with GNU General Public License v3.0 5 votes vote down vote up
def test11DeleteUser(self):
        self.loginAdmin()
        WebDriverWait(self.browser, 5).until(EC.presence_of_element_located((By.LINK_TEXT, 'admin page')))
        self.browser.find_element_by_link_text('admin page').click()
        WebDriverWait(self.browser, 5).until(EC.presence_of_element_located((By.XPATH, '//button[@onclick="showUserDetails(\'testuser2\');"]')))
        self.browser.find_element_by_xpath('//button[@onclick="showUserDetails(\'testuser2\');"]').click()
        WebDriverWait(self.browser, 5).until(EC.presence_of_element_located((By.XPATH, '//button[@onclick="deleteUser(\'testuser2\')"]')))
        self.browser.find_element_by_xpath('//button[@onclick="deleteUser(\'testuser2\')"]').click()
        WebDriverWait(self.browser, 5).until(EC.alert_is_present())
        Alert(self.browser).send_keys('CONFIRM')
        Alert(self.browser).accept()
        WebDriverWait(self.browser, 5).until(EC.presence_of_element_located((By.ID, 'usertable')))
        self.assertFalse(len(self.browser.find_elements_by_xpath('//button[@onclick="showUserDetails(\'testuser2\');"]'))) 
Example #24
Source File: run_server_tests.py    From anvio with GNU General Public License v3.0 5 votes vote down vote up
def test07SelectProject(self):
        self.login()
        WebDriverWait(self.browser, 5).until(EC.presence_of_element_located((By.LINK_TEXT, 'test_project_with_all_files')))
        self.browser.find_element_by_link_text('test_project_with_all_files').click()
        WebDriverWait(self.browser, 5).until(EC.title_is('test_project_with_all_files'))
        self.assertIn('test_project_with_all_files', self.browser.title) 
Example #25
Source File: run_server_tests.py    From anvio with GNU General Public License v3.0 5 votes vote down vote up
def test06CreateNewProjectWithMinimalInput(self):
        self.login()
        WebDriverWait(self.browser, 5).until(EC.visibility_of_element_located((By.XPATH, '//button[@title="upload data files"]')))

        self.browser.find_element_by_xpath('//button[@title="upload data files"]').click()
        WebDriverWait(self.browser, 5).until(EC.visibility_of_element_located((By.ID, 'uploadTitle')))
        self.browser.find_element_by_id('uploadTitle').send_keys('test_project_minimal')
        self.browser.find_element_by_id('uploadDescription').send_keys('description of test project')
        self.browser.find_element_by_id('treeFileSelect').send_keys(self.BASEPATH+'tree.txt')
        self.browser.find_element_by_id('dataFileSelect').send_keys(self.BASEPATH+'view_data.txt')
        self.browser.find_element_by_id('uploadFiles').click()
        WebDriverWait(self.browser, 5).until(EC.presence_of_element_located((By.LINK_TEXT, 'test_project_minimal')))
        self.assertTrue(self.browser.find_element_by_link_text('test_project_minimal')) 
Example #26
Source File: run_server_tests.py    From anvio with GNU General Public License v3.0 5 votes vote down vote up
def test05CreateNewProjectWithAllFiles(self):
        self.login()
        WebDriverWait(self.browser, 5).until(EC.visibility_of_element_located((By.XPATH, '//button[@title="upload data files"]')))

        self.browser.find_element_by_xpath('//button[@title="upload data files"]').click()
        WebDriverWait(self.browser, 5).until(EC.visibility_of_element_located((By.ID, 'uploadTitle')))
        self.browser.find_element_by_id('uploadTitle').send_keys('test_project_with_all_files')
        self.browser.find_element_by_id('uploadDescription').send_keys('description of test project')
        self.browser.find_element_by_id('treeFileSelect').send_keys(self.BASEPATH+'tree.txt')
        self.browser.find_element_by_id('fastaFileSelect').send_keys(self.BASEPATH+'fasta.fa')
        self.browser.find_element_by_id('dataFileSelect').send_keys(self.BASEPATH+'view_data.txt')
        self.browser.find_element_by_id('samplesOrderFileSelect').send_keys(self.BASEPATH+'samples-order.txt')
        self.browser.find_element_by_id('samplesInformationFileSelect').send_keys(self.BASEPATH+'samples-information.txt')
        self.browser.find_element_by_id('uploadFiles').click()
        WebDriverWait(self.browser, 5).until(EC.presence_of_element_located((By.LINK_TEXT, 'test_project_with_all_files')))
        self.assertTrue(self.browser.find_element_by_link_text('test_project_with_all_files')) 
Example #27
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) 
Example #28
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 #29
Source File: stockplanconnect.py    From finance-dl with GNU General Public License v2.0 4 votes vote down vote up
def download_documents(self):
        logger.info('Looking for PDF links')
        links, = self.wait_and_return(
            lambda: self.driver.find_elements(By.LINK_TEXT, 'PDF'))
        links = list(links)[::-1]
        previously_seen_parts = collections.Counter()
        for link in links:
            cur_el = link
            output_path = None
            while True:
                try:
                    parent = cur_el.find_element_by_xpath('..')
                except:
                    break
                if parent == cur_el:
                    break
                full_text = parent.text
                parts = full_text.split('\n')
                if len(parts) == 5:
                    try:
                        key = tuple(parts)
                        index = previously_seen_parts[key] + 1
                        previously_seen_parts[key] += 1
                        output_path = self.get_output_path(parts, index)
                        break
                    except:
                        logger.info('Failed to determine output filename %r',
                                    parts)
                        break
                else:
                    cur_el = parent
            if output_path is None:
                logger.info('skipping link due to no date')
                continue
            if os.path.exists(output_path):
                logger.info('skipping existing file: %r', output_path)
                continue

            self.click(link)
            logger.info('Waiting for download')
            download_result, = self.wait_and_return(self.get_downloaded_file)

            if not os.path.exists(self.output_directory):
                os.makedirs(self.output_directory)

            tmp_path = output_path + '.tmp'
            with open(tmp_path, 'wb') as f:
                download_data = download_result[1]
                f.write(download_data)
            os.rename(tmp_path, output_path)
            logger.info("Wrote %s", output_path) 
Example #30
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