Python selenium.webdriver.common.keys.Keys 模块,DOWN 实例源码

我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用selenium.webdriver.common.keys.Keys.DOWN

项目:golem    作者:lucianopuccio    | 项目源码 | 文件源码
def press_key(element, key):
    """Press a given key in the element.
    Parameters:
    element : element
    key : value
    """
    step_message = 'Press key: {}'.format(key)
    execution.logger.info(step_message)
    _capture_or_add_step(step_message, execution.settings['screenshot_on_step'])
    webelement = get_browser().find(element)
    if key == 'RETURN' or key == 'ENTER':
        webelement.send_keys(Keys.RETURN)
    elif key == 'UP':
        webelement.send_keys(Keys.UP)
    elif key == 'DOWN':
        webelement.send_keys(Keys.DOWN)
    elif key == 'LEFT':
        webelement.send_keys(Keys.LEFT)
    elif key == 'RIGHT':
        webelement.send_keys(Keys.RIGHT)
    else:
        raise Exception('Key value {} is invalid'.format(key))
项目:base_function    作者:Rockyzsu    | 项目源码 | 文件源码
def key_operation():
    # ????
    options = webdriver.ChromeOptions()
    options.add_argument(
        '--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36')
    browser = webdriver.Chrome(executable_path=r'C:\software\chrome\chromedriver.exe',
                               chrome_options=options)  #
    browser.implicitly_wait(60)

    browser.get('https://m.fang.com/fangjia/sz_list_pinggu/')
    #browser.send_keys(Keys.DOWN)
    count=0
    while count<190:

        browser.find_element_by_xpath("//body[@class='whitebg']").send_keys(Keys.PAGE_DOWN)
        time.sleep(5)
        count=count+1
    raw_input('enter')
项目:base_function    作者:Rockyzsu    | 项目源码 | 文件源码
def shop():
    options = webdriver.ChromeOptions()
    options.add_argument(
        '--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36')
    options.add_argument('--headless')
    options.add_argument('--disable-gpu')
    browser = webdriver.Chrome(executable_path=r'E:\OneDrive\Python\selenium\chromedriver.exe',
                               chrome_options=options)

    browser.implicitly_wait(60)
    url='http://shop.99114.com/'
    browser.get(url)
    time.sleep(5)
    txt=browser.page_source

    print txt

    #browser.send_keys(Keys.DOWN)

#netease()
#anjuke()

#key_operation()
项目:micromasters    作者:mitodl    | 项目源码 | 文件源码
def test_switch_program(self, browser, base_test_data, logged_in_staff):
        """
        Switching programs should show a different set of users
        """
        existing_program_user_count = settings.ELASTICSEARCH_DEFAULT_PAGE_SIZE
        create_enrolled_user_batch(existing_program_user_count, program=base_test_data.program, is_staff=False)

        new_program = ProgramFactory.create(live=True)
        new_program_user_count = settings.ELASTICSEARCH_DEFAULT_PAGE_SIZE - 1
        create_enrolled_user_batch(new_program_user_count, program=new_program, is_staff=False)
        ProgramEnrollment.objects.create(program=new_program, user=logged_in_staff)
        Role.objects.create(
            role=Staff.ROLE_ID,
            user=logged_in_staff,
            program=new_program,
        )

        # Load the learners page for the existing program
        browser.get("/learners")
        browser.wait_until_element_count(By.CLASS_NAME, 'learner-result', existing_program_user_count)
        # Switch programs and check that the correct number of users are returned
        switcher = browser.driver.find_element_by_css_selector('.micromasters-header .Select-input')
        switcher.send_keys(Keys.DOWN)
        switcher.send_keys(Keys.ENTER)
        browser.wait_until_element_count(By.CLASS_NAME, 'learner-result', new_program_user_count)
        # Refresh browser and verify the count is the same
        browser.get("/learners")
        browser.wait_until_element_count(By.CLASS_NAME, 'learner-result', new_program_user_count)
项目:Adidas-Automated-checkout-bot    作者:tj203539    | 项目源码 | 文件源码
def RunBot():
    '''opens web browser'''
    chromedriver = "/Users/Tj/Downloads/chromedriver"
    os.environ["webdriver.chrome.driver"] = chromedriver
    driver = webdriver.Chrome(chromedriver)
    driver.get(Shoe_url)
    add_to_cart = driver.find_element_by_name('add-to-cart-button')
    add_to_cart.click()
    time.sleep(5)
    checkout = driver.find_element_by_css_selector('.adi-gradient-blue')
    checkout.click()
    first_name_Elem = driver.find_element_by_id('dwfrm_delivery_singleshipping_shippingAddress_addressFields_firstName')
    first_name_Elem.send_keys(first_name)
    last_name_Elem = driver.find_element_by_id('dwfrm_delivery_singleshipping_shippingAddress_addressFields_lastName')
    last_name_Elem.send_keys(last_name)
    address_Elem = driver.find_element_by_id('dwfrm_delivery_singleshipping_shippingAddress_addressFields_address1')
    address_Elem.send_keys(street_address)
    city_Elem = driver.find_element_by_id('dwfrm_delivery_singleshipping_shippingAddress_addressFields_city')
    city_Elem.send_keys(city)
    zip_code_Elem = driver.find_element_by_id('dwfrm_delivery_singleshipping_shippingAddress_addressFields_zip')
    zip_code_Elem.send_keys(zip_code)
    phone_number_Elem = driver.find_element_by_id('dwfrm_delivery_singleshipping_shippingAddress_addressFields_phone')
    phone_number_Elem.send_keys(phone_number)
    email_Elem = driver.find_element_by_id('dwfrm_delivery_singleshipping_shippingAddress_email_emailAddress')
    email_Elem.send_keys(email)
    state_dropdown = driver.find_element_by_css_selector('.ffSelectButton')
    state_dropdown.click()
    state_dropdown.send_keys(Keys.DOWN * S)
    state_dropdown.send_keys(Keys.ENTER)
    pay = driver.find_element_by_css_selector("#dwfrm_delivery_savedelivery")
    pay.click()
    time.sleep(3)
    name_oncard_Elem = driver.find_element_by_id('dwfrm_payment_creditCard_owner')
    name_oncard_Elem.clear()
    name_oncard_Elem.send_keys(first_name + ' ' + last_name)
    card_number_Elem = driver.find_element_by_id('dwfrm_payment_creditCard_number')
    card_number_Elem.send_keys(card_number)
    security_code_Elem = driver.find_element_by_id('dwfrm_payment_creditCard_cvn')
    security_code_Elem.send_keys(security_code)
    actions = webdriver.ActionChains(driver)
    month_dropdown = driver.find_element_by_css_selector('.ffSelectButton')
    month_dropdown.click()
    month_dropdown.send_keys(Keys.DOWN * M)
    month_dropdown.send_keys(Keys.ENTER)
    year_select = driver.find_element_by_css_selector('.year')
    actions.move_to_element(year_select)
    actions.click()
    actions.send_keys(Keys.DOWN * Y)
    actions.send_keys(Keys.ENTER)
    actions.perform()
    security_code_Elem = driver.find_element_by_id('dwfrm_payment_creditCard_cvn')
    security_code_Elem.send_keys(security_code)
    security_code_Elem.send_keys(Keys.TAB * 5)
    time.sleep(3)