當前位置: 首頁>>代碼示例>>Python>>正文


Python Keys.DOWN屬性代碼示例

本文整理匯總了Python中selenium.webdriver.common.keys.Keys.DOWN屬性的典型用法代碼示例。如果您正苦於以下問題:Python Keys.DOWN屬性的具體用法?Python Keys.DOWN怎麽用?Python Keys.DOWN使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在selenium.webdriver.common.keys.Keys的用法示例。


在下文中一共展示了Keys.DOWN屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: play

# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import DOWN [as 別名]
def play():
    """
    Args:
        None
    Returns:
        None
    """
    driver = webdriver.Firefox(executable_path='/Users/keneudeh/Downloads/geckodriver')
    driver.get('https://play2048.co/')

    key_select = [Keys.UP, Keys.DOWN, Keys.LEFT, Keys.RIGHT]

    gameStatusElem = driver.find_element_by_css_selector('.game-container p')
    htmlElem = driver.find_element_by_css_selector('html')
    

    while gameStatusElem.text != 'Game over!':
        
        htmlElem.send_keys(key_select[random.randint(0, 3)])
        gameStatusElem = driver.find_element_by_css_selector('.game-container p')

    score = driver.find_element_by_css_selector('.score-container').text

    print(f'You scored: {score}') 
開發者ID:kudeh,項目名稱:automate-the-boring-stuff-projects,代碼行數:26,代碼來源:2048.py

示例2: read_new_article

# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import DOWN [as 別名]
def read_new_article(self):
        article_url = 'https://www.xuexi.cn/lgdata/1jscb6pu1n2.json'

        try:
            resp = requests.get(article_url, proxies=config['proxies'] if config['use_proxy'] else {})
        except Exception:
            raise TimeoutError('Timeout')

        resp_list = eval(resp.text)

        self.__exit_flag.clear()

        for link in resp_list:
            try:
                if not read_check(link['itemId'], 'article'):
                    continue

                self.driver.get(link['url'])
                app.log(u'正在學習文章:%s' % link['title'])
                while not self.__exit_flag.isSet():
                    ActionChains(self.driver).key_down(Keys.DOWN).perform()

                    self.driver.execute_script("""
                        (function(){
                            if (document.documentElement.scrollTop + document.documentElement.clientHeight  >= document.documentElement.scrollHeight*0.9){
                                document.title = 'scroll-done';}
                            })();
                            """)
                    if u'scroll-done' in self.driver.title:
                        break
                    else:
                        self.__exit_flag.wait(random.randint(2, 5))
                app.log(u'%s 學習完畢' % link['title'])
                yield True
            except Exception as error:
                logging.debug(error)
                yield False 
開發者ID:zodiac182,項目名稱:autoxuexi,代碼行數:39,代碼來源:xuexi.py

示例3: test_history_in_console

# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import DOWN [as 別名]
def test_history_in_console(self, notebook):
        notebook.edit_prompt_cell("a = 1", execute=True)
        assert "" == notebook.get_prompt_content()
        notebook.edit_prompt_cell("b <- 2", kernel="R", execute=True)
        assert "" == notebook.get_prompt_content()
        notebook.prompt_cell.send_keys(Keys.UP)
        assert "b <- 2" == notebook.get_prompt_content()
        notebook.prompt_cell.send_keys(Keys.UP)
        assert "a = 1" == notebook.get_prompt_content()
        # FIXME: down keys does not work, perhaps because the cell is not focused and
        # the first step would be jumping to the end of the line
        notebook.prompt_cell.send_keys(Keys.DOWN)
        notebook.prompt_cell.send_keys(Keys.DOWN)
        #  assert 'b <- 2' == notebook.get_prompt_content() 
開發者ID:vatlab,項目名稱:sos-notebook,代碼行數:16,代碼來源:test_frontend.py

示例4: test_switch_program

# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import DOWN [as 別名]
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) 
開發者ID:mitodl,項目名稱:micromasters,代碼行數:30,代碼來源:basic_test.py


注:本文中的selenium.webdriver.common.keys.Keys.DOWN屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。