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


Python Keys.RIGHT屬性代碼示例

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


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

示例1: play

# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import RIGHT [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: test_timestamp_buckets

# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import RIGHT [as 別名]
def test_timestamp_buckets(self):
        survey_id = self.survey_with_branch(
            'timestamp',
            '(2015-01-01T12:00:00Z, 2015-01-03T12:00:00Z)',
            '[2015-01-04T12:00:00Z, 2015-01-05T12:00:00Z]'
        )

        self.get('/enumerate/{}'.format(survey_id))
        self.wait_for_element('navigate-right', By.CLASS_NAME)
        self.click(self.drv.find_element_by_class_name('navigate-right'))
        self.enter_timestamp(
            self.drv.find_element_by_tag_name('input'),
            '2015-01-02T12:00:00'
        )
        self.click(self.drv.find_element_by_class_name('navigate-right'))
        self.assertEqual(
            self.drv.find_element_by_tag_name('h3').text,
            'b0'
        )
        self.click(self.drv.find_element_by_class_name('page_nav__prev'))
        self.input_field().send_keys(Keys.RIGHT * 30, Keys.BACK_SPACE * 30)
        self.enter_timestamp(
            self.drv.find_element_by_tag_name('input'),
            '2015-01-04T12:00:00'
        )
        self.click(self.drv.find_element_by_class_name('navigate-right'))
        self.assertEqual(
            self.drv.find_element_by_tag_name('h3').text,
            'b1'
        )
        self.click(self.drv.find_element_by_class_name('page_nav__prev'))
        self.input_field().send_keys(Keys.RIGHT * 30, Keys.BACK_SPACE * 30)
        self.enter_timestamp(
            self.drv.find_element_by_tag_name('input'),
            '2015-01-01T12:00:00'
        )
        self.click(self.drv.find_element_by_class_name('navigate-right'))
        self.assertEqual(
            self.drv.find_element_by_tag_name('h3').text,
            'last question'
        ) 
開發者ID:SEL-Columbia,項目名稱:dokomoforms,代碼行數:43,代碼來源:test_selenium.py

示例3: test_timestamp_buckets_open_ranges

# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import RIGHT [as 別名]
def test_timestamp_buckets_open_ranges(self):
        survey_id = self.survey_with_branch(
            'timestamp',
            '(, 2015-01-01T1:00:00Z)',
            '[2015-01-10T1:00:00Z,]'
        )

        self.get('/enumerate/{}'.format(survey_id))
        self.wait_for_element('navigate-right', By.CLASS_NAME)
        self.click(self.drv.find_element_by_class_name('navigate-right'))
        self.enter_timestamp(
            self.drv.find_element_by_tag_name('input'),
            '2014-11-22T01:00:00'
        )
        self.click(self.drv.find_element_by_class_name('navigate-right'))
        self.assertEqual(
            self.drv.find_element_by_tag_name('h3').text,
            'b0'
        )
        self.click(self.drv.find_element_by_class_name('page_nav__prev'))
        self.input_field().send_keys(Keys.RIGHT * 30, Keys.BACK_SPACE * 30)
        self.enter_timestamp(
            self.drv.find_element_by_tag_name('input'),
            '2015-11-22T01:00:00'
        )
        self.click(self.drv.find_element_by_class_name('navigate-right'))
        self.assertEqual(
            self.drv.find_element_by_tag_name('h3').text,
            'b1'
        )
        self.click(self.drv.find_element_by_class_name('page_nav__prev'))
        self.input_field().send_keys(Keys.RIGHT * 30, Keys.BACK_SPACE * 30)
        self.enter_timestamp(
            self.drv.find_element_by_tag_name('input'),
            '2015-01-05T01:00:00'
        )
        self.click(self.drv.find_element_by_class_name('navigate-right'))
        self.assertEqual(
            self.drv.find_element_by_tag_name('h3').text,
            'last question'
        ) 
開發者ID:SEL-Columbia,項目名稱:dokomoforms,代碼行數:43,代碼來源:test_selenium.py

示例4: test_timestamp_buckets_total_open

# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import RIGHT [as 別名]
def test_timestamp_buckets_total_open(self):
        survey_id = self.survey_with_branch('timestamp', '(,)')

        self.get('/enumerate/{}'.format(survey_id))
        self.wait_for_element('navigate-right', By.CLASS_NAME)
        self.click(self.drv.find_element_by_class_name('navigate-right'))
        self.enter_timestamp(
            self.drv.find_element_by_tag_name('input'),
            '1970-01-05T01:00:00'
        )
        self.click(self.drv.find_element_by_class_name('navigate-right'))
        self.assertEqual(
            self.drv.find_element_by_tag_name('h3').text,
            'b0'
        )
        self.click(self.drv.find_element_by_class_name('page_nav__prev'))
        self.input_field().send_keys(Keys.RIGHT * 30, Keys.BACK_SPACE * 30)
        self.enter_timestamp(
            self.drv.find_element_by_tag_name('input'),
            '2070-01-05T01:00:00'
        )
        self.click(self.drv.find_element_by_class_name('navigate-right'))
        self.assertEqual(
            self.drv.find_element_by_tag_name('h3').text,
            'b0'
        ) 
開發者ID:SEL-Columbia,項目名稱:dokomoforms,代碼行數:28,代碼來源:test_selenium.py

示例5: test_required_question_bad_answer

# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import RIGHT [as 別名]
def test_required_question_bad_answer(self):
        user = (
            self.session
            .query(Administrator)
            .get('b7becd02-1a3f-4c1d-a0e1-286ba121aef4')
        )
        node = (
            self.session
            .query(Node)
            .filter(Node.title['English'].astext == 'integer_node')
            .one()
        )
        with self.session.begin():
            survey = construct_survey(
                creator=user,
                survey_type='public',
                title={'English': 'required question'},
                nodes=[
                    construct_survey_node(
                        required=True,
                        node=node,
                    ),
                ],
            )
            self.session.add(survey)

        survey_id = survey.id

        self.get('/enumerate/{}'.format(survey_id))
        self.wait_for_element('navigate-right', By.CLASS_NAME)
        self.click(self.drv.find_element_by_class_name('navigate-right'))

        (
            self.drv
            .find_element_by_tag_name('input')
            .send_keys('not an integer')
        )
        self.click(self.drv.find_element_by_class_name('navigate-right'))

        # An alert pops up
        # TODO: change this behavior
        alert = self.drv.switch_to.alert
        alert.accept()

        self.input_field().send_keys(
            Keys.RIGHT * 14, Keys.BACK_SPACE * 14, '3'
        )

        self.click(self.drv.find_element_by_class_name('navigate-right'))
        self.click(self.drv.find_element_by_class_name('navigate-right'))
        self.click(self.drv.find_elements_by_tag_name('button')[0])

        new_submission = self.get_last_submission(survey_id)

        self.assertEqual(new_submission.answers[0].answer, 3) 
開發者ID:SEL-Columbia,項目名稱:dokomoforms,代碼行數:57,代碼來源:test_selenium.py

示例6: naver_full

# 需要導入模塊: from selenium.webdriver.common.keys import Keys [as 別名]
# 或者: from selenium.webdriver.common.keys.Keys import RIGHT [as 別名]
def naver_full(self, keyword, add_url=""):
        print('[Full Resolution Mode]')

        self.browser.get("https://search.naver.com/search.naver?where=image&sm=tab_jum&query={}{}".format(keyword, add_url))
        time.sleep(1)

        elem = self.browser.find_element_by_tag_name("body")

        print('Scraping links')

        self.wait_and_click('//div[@class="img_area _item"]')
        time.sleep(1)

        links = []
        count = 1

        last_scroll = 0
        scroll_patience = 0

        while True:
            try:
                xpath = '//div[@class="image_viewer_wrap _sauImageViewer"]//img[@class="_image_source"]'
                imgs = self.browser.find_elements(By.XPATH, xpath)

                for img in imgs:
                    self.highlight(img)
                    src = img.get_attribute('src')

                    if src not in links and src is not None:
                        links.append(src)
                        print('%d: %s' % (count, src))
                        count += 1

            except StaleElementReferenceException:
                # print('[Expected Exception - StaleElementReferenceException]')
                pass
            except Exception as e:
                print('[Exception occurred while collecting links from naver_full] {}'.format(e))

            scroll = self.get_scroll()
            if scroll == last_scroll:
                scroll_patience += 1
            else:
                scroll_patience = 0
                last_scroll = scroll

            if scroll_patience >= 30:
                break

            elem.send_keys(Keys.RIGHT)

        links = self.remove_duplicates(links)

        print('Collect links done. Site: {}, Keyword: {}, Total: {}'.format('naver_full', keyword, len(links)))
        self.browser.close()

        return links 
開發者ID:YoongiKim,項目名稱:AutoCrawler,代碼行數:59,代碼來源:collect_links.py


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