How to use the selenium.webdriver.common.keys.Keys function in selenium

To help you get started, we’ve selected a few selenium examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github exa-analytics / exatomic / test_widget.py View on Github external
lambda driver: len(initial_handles) != len(driver.window_handles)
        )
        # switch to new notebook
        driver.switch_to.window(driver.window_handles[1])

        # select the first input cell
        cell = '#notebook-container > div > div.input > div.inner_cell > div.input_area'
        click_by_css(driver, wait, cell)

        # input some text
        run = 'import exatomic; exatomic.widgets.widget_base.Scene()'
        ActionChains(driver).send_keys(run).perform()
        [cell] = driver.find_elements_by_css_selector(cell)

        # execute the cell
        (ActionChains(driver).key_down(Keys.SHIFT).key_down(Keys.ENTER)
                             .key_up(Keys.SHIFT).key_up(Keys.ENTER).perform())
        print('should show widget now')

        # touch the rendered canvas
        scene = ('#notebook-container > div.cell.code_cell.rendered.unselected > div.output_wrapper '
                 '> div.output > div > div.output_subarea.jupyter-widgets-view > div > canvas')
        click_by_css(driver, wait, scene)

        driver.get_screenshot_as_file(f'{TOKEN}/widget.png')

        print('interacted with scene')

        # shut down the new notebook
        menu = '#filelink'
        click_by_css(driver, wait, menu)
        print('clicked on file menu button')
github authomatic / authomatic / tests / functional_tests / fixtures / providers.py View on Github external
def f(browser):
            if self.LOGIN_XPATH:
                for xpath in self.PRE_LOGIN_CLICKS_XPATH:
                    print('clicking on {0}'.format(xpath))
                    browser.find_element_by_xpath(xpath).click()

                print('logging the user in.')
                browser.find_element_by_xpath(self.LOGIN_XPATH)\
                    .send_keys(self.login)
                password_element = browser.\
                    find_element_by_xpath(self.PASSWORD_XPATH)
                print 'PASSWORD = {0}'.format(self.password)
                password_element.send_keys(self.password)
                password_element.send_keys(Keys.ENTER)
        return f
github xtk / X / utils / _core / _tester.py View on Github external
# keyboard events
    #

    # rotate      
    for i in range( 30 ):
      actions.send_keys( Keys.ARROW_RIGHT )
    for i in range( 30 ):
      actions.send_keys( Keys.ARROW_UP )
    for i in range( 30 ):
      actions.send_keys( Keys.ARROW_LEFT )
    for i in range( 30 ):
      actions.send_keys( Keys.ARROW_DOWN )

    # zoom
    for i in range( 50 ):
      actions.key_down( Keys.LEFT_ALT )
      actions.send_keys( Keys.ARROW_LEFT )

    for i in range( 25 ):
      actions.key_down( Keys.LEFT_ALT )
      actions.send_keys( Keys.ARROW_RIGHT )

    # pan
    actions.key_down( Keys.LEFT_SHIFT )
    actions.send_keys( Keys.ARROW_RIGHT, Keys.ARROW_RIGHT, Keys.ARROW_RIGHT )
    actions.key_down( Keys.LEFT_SHIFT )
    actions.send_keys( Keys.ARROW_LEFT, Keys.ARROW_LEFT, Keys.ARROW_LEFT )
    actions.key_down( Keys.LEFT_SHIFT )
    actions.send_keys( Keys.ARROW_UP, Keys.ARROW_UP, Keys.ARROW_UP )
    actions.key_down( Keys.LEFT_SHIFT )
    actions.send_keys( Keys.ARROW_DOWN, Keys.ARROW_DOWN )
github kamushadenes / bankscraper / bankscraper / santander.py View on Github external
elem = self.wait.until(EC.visibility_of_element_located((By.NAME, 'txtCPF')))
            elem.send_keys(self.account.document)
            elem.send_keys(Keys.ENTER)

            sleep(3)

            self.session.switch_to.frame(self.wait.until(EC.visibility_of_element_located((By.NAME, 'Principal'))))
            self.session.switch_to.frame(self.wait.until(EC.visibility_of_element_located((By.NAME, 'MainFrame'))))

            if 'iframeContrato' in self.session.page_source:
                print('[-] You need to manually accept an usage agreement')
                exit(1)

            elem = self.wait.until(EC.visibility_of_element_located((By.ID, 'txtSenha')))
            elem.send_keys(self.account.password)
            elem.send_keys(Keys.ENTER)

            self.session.switch_to.default_content()
            self.session.switch_to.frame(self.wait.until(EC.visibility_of_element_located((By.NAME, 'Principal'))))
            self.session.switch_to.frame(self.wait.until(EC.visibility_of_element_located((By.NAME, 'Corpo'))))

            ola = self.session.find_element_by_id('ola')

            soup = bs(ola.get_attribute('innerHTML'))

            table = soup.find('table')

            self.account.owner = Owner(table.find_all('td')[0].find('strong').text.strip())
            self.account.owner.document = self.account.document

            self.account.branch = table.find_all('td')[1].text.split()[1]
            self.account.number = ''.join(table.find_all('td')[1].text.split()[3].split('.')[:2])
github kjam / wswp / code / chp6 / selenium_forms.py View on Github external
def login(driver):
    driver.get(LOGIN_URL)
    driver.find_element_by_id('auth_user_email').send_keys(LOGIN_EMAIL)
    driver.find_element_by_id('auth_user_password').send_keys(
        LOGIN_PASSWORD + Keys.RETURN)
    pg_loaded = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID, "results")))
    assert 'login' not in driver.current_url
github gil9red / SimplePyScripts / selenium__examples / about_wait / explicit_waits.py View on Github external
# finally:
#     driver.quit()


# pip install selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

driver = webdriver.Firefox()
driver.get('https://www.youtube.com/')
print('Title: "{}"'.format(driver.title))

driver.find_element_by_css_selector('input#search').send_keys('Funny cats' + Keys.RETURN)

wait = WebDriverWait(driver, timeout=10)

result_count = wait.until(
    EC.presence_of_element_located((By.ID, 'result-count'))
)
print(result_count.text)

print('Title: "{}"'.format(driver.title))

video_list = driver.find_elements_by_id('dismissable')

# Click on random video
import random
random.choice(video_list).click()
github rcbyron / hey-athena-client / athena / api_library / spotify_api.py View on Github external
show_results = WebDriverWait(self.driver, 10).until(
                    EC.presence_of_element_located((By.XPATH, '//*[@class="results"]/descendant::a'))
            )
            show_results.click()
            self.driver.switch_to_default_content()
            wrapper = WebDriverWait(self.driver, 10).until(
                    EC.presence_of_element_located((By.CLASS_NAME, 'front'))
            )
            iframe = wrapper.find_element_by_tag_name('iframe')
            self.driver.switch_to_frame(iframe)
            songs = WebDriverWait(self.driver, 10).until(
                    EC.presence_of_element_located((By.TAG_NAME, 'tbody'))
            )
            first_song = songs.find_element_by_tag_name('tr')
            first_song.click()
            first_song.send_keys(Keys.RETURN)
        except:
            print('Can\'t find element...')
            print(traceback.format_exc())
github okfn-brasil / open-jus / justa / crawler / justa / spiders / distrito_federal.py View on Github external
def start_page(self, page=1):
        button = '#botao_pesquisar'
        self.browser.visit(self.url)
        assert self.browser.is_element_present_by_css(button, wait_time=60)
        self.browser.find_by_css(button).click()

        if page > 1:
            field = '#numeroDaPaginaAtual'
            assert self.browser.is_element_present_by_css(field, wait_time=60)

            # We need to send some keys, something not implemented in Splinter
            # yet, but that will be possible soon:
            # https://github.com/cobrateam/splinter/issues/572
            # While this isn't possible we access the original Selenium element
            paginator = self.browser.find_by_css(field).first._element
            paginator.send_keys(Keys.CONTROL + "a");
            paginator.send_keys(Keys.DELETE);
            paginator.send_keys(page)
            paginator.send_keys(Keys.ENTER)
github dscovr / pyinstamation / pyinstamation / scrapper / insta_scrapper.py View on Github external
def _format_image(self):
        element = WebDriverWait(self.browser, 10).until(
            EC.presence_of_element_located((
                By.XPATH, const.UPLOAD_PICTURE_NEXT_LINK)))
        element.send_keys(Keys.ESCAPE)
        element.click()
        save_page_source(self.current_url.path, self.page_source)
        return True
github IFinners / automate-the-boring-stuff-projects / Chapter 11 / 2048.py View on Github external
#!/usr/bin/env/ python3

"""Automatically plays the game 2048."""

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

browser = webdriver.Firefox()
browser.get('https://gabrielecirulli.github.io/2048/')
html_elem = browser.find_element_by_tag_name('html')

while True:
    html_elem.send_keys(Keys.UP)
    html_elem.send_keys(Keys.RIGHT)
    html_elem.send_keys(Keys.DOWN)
    html_elem.send_keys(Keys.LEFT)