python类ActionChains()的实例源码

article_common.py 文件源码 项目:directory-tests 作者: uktrade 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def go_to_article(driver: webdriver, title: str):
    with selenium_action(driver, "Could not find article: %s", title):
        article = driver.find_element_by_link_text(title)
        if "firefox" not in driver.capabilities["browserName"].lower():
            logging.debug("Moving focus to '%s' article link", title)
            action_chains = ActionChains(driver)
            action_chains.move_to_element(article)
            action_chains.perform()
    with assertion_msg(
            "Found a link to '%s' article but it's not visible", title):
        assert article.is_displayed()
    article.click()
    take_screenshot(driver, "After going to the '{}' Article".format(title))
article_common.py 文件源码 项目:directory-tests 作者: uktrade 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_read_counter(driver: webdriver) -> int:
    with selenium_action(driver, "Could not find Article Read Counter"):
        counter = driver.find_element_by_css_selector(ARTICLES_TO_READ_COUNTER)
        if "firefox" not in driver.capabilities["browserName"].lower():
            logging.debug("Moving focus to Article Read Counter")
            action_chains = ActionChains(driver)
            action_chains.move_to_element(counter)
            action_chains.perform()
    with assertion_msg("Article Read Counter is not visible"):
        assert counter.is_displayed()
    return int(counter.text)
test_reconcile.py 文件源码 项目:biweeklybudget 作者: jantman 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_06_success(self, base_url, selenium):
        self.baseurl = base_url
        self.get(selenium, base_url + '/reconcile')
        src = selenium.find_element_by_id('ofx-2-OFX3')
        tgt = selenium.find_element_by_id(
            'trans-3').find_element_by_class_name('reconcile-drop-target')
        # drag and drop
        chain = ActionChains(selenium)
        chain.drag_and_drop(src, tgt).perform()
        # ensure that the OFX div was hidden in the OFX column
        src = selenium.find_element_by_id('ofx-2-OFX3')
        assert src.is_displayed() is False
        # ensure that the OFX div was placed in the drop target
        tgt = selenium.find_element_by_id('trans-3')
        expected = txn_div(
            3,
            date(2017, 4, 11),
            600,
            'BankTwo', 2,
            '2Periodic', 2,
            'trans2',
            drop_div=ofx_div(
                date(2017, 4, 9),
                600.00,
                'BankTwo', 2,
                'Purchase',
                'OFX3',
                'ofx3-trans2-st1',
                trans_id=3
            )
        )
        assert self.normalize_html(tgt.get_attribute('outerHTML')) == expected
        # ensure the reconciled variable was updated
        assert self.get_reconciled(selenium) == {
            3: [2, 'OFX3']
        }
middlewares.py 文件源码 项目:Spider 作者: poluo 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__(self):
        self.cookies = None
        path = "C:\Program Files (x86)\Google\Chrome\chromedriver.exe"
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument("--incognito")
        self.driver = webdriver.Chrome(service_args=['--load-images=no'], executable_path=path,
                                       chrome_options=chrome_options)
        self.action = ActionChains(self.driver)
        self.retry_login()
page_taobao.py 文件源码 项目:spider 作者: luanxiangming 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def goto_profile_page(self):

        my = self.waitUntilFindElement(MainPageLocators.MY)
        account = self.waitUntilFindElement(MainPageLocators.ACCOUNT)

        actions = ActionChains(self.driver)
        actions.move_to_element(my).perform()
        actions.click(account).perform()
        # ActionChains(self.driver).move_to_element(my).click(account).perform()
test_t1_16_CreateAHomework.py 文件源码 项目:test-automation 作者: openstax 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_teacher_add_a_homework_using_the_calendar_date_8029(self):
        """Add a homework using the calendar date.

        Steps:
        Click on a date at least one day later than current date on calendar
        From the menu that appears, click on 'Add Homework'

        Expected Result:
        The teacher is taken to a page where they create the assignment.
        """
        self.ps.test_updates['name'] = 't1.16.002' \
            + inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates['tags'] = ['t1', 't1.16', 't1.16.002', '8028']
        self.ps.test_updates['passed'] = False

        # Test steps and verification assertions
        calendar_date = self.teacher.wait.until(
            expect.element_to_be_clickable(
                (By.XPATH, '//div[contains(@class,"Day--upcoming")]')
            )
        )
        self.teacher.driver.execute_script(
            'return arguments[0].scrollIntoView();', calendar_date)
        self.teacher.driver.execute_script('window.scrollBy(0, -80);')
        self.teacher.sleep(2)
        actions = ActionChains(self.teacher.driver)
        actions.move_to_element(calendar_date)
        actions.move_by_offset(0, -35)
        actions.click()
        actions.move_by_offset(30, 45)
        actions.click()
        actions.perform()
        assert('homework/new' in self.teacher.current_url()),\
            'not at Add Homework page'

        self.ps.test_updates['passed'] = True

    # Case C8030 - 003 - Teacher | Set open/due dates for periods collectively
test_t1_21_CreateAnEvent.py 文件源码 项目:test-automation 作者: openstax 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_teacher_add_event_using_the_calendar_date_8119(self):
        """Add an event using the calendar date.

        Steps:
        Click on a calendar date
        Click on the 'Add Event' option

        Expected Result:
        user taken to add ecent page with due date filled in
        """
        self.ps.test_updates['name'] = 't1.21.003' \
            + inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates['tags'] = ['t1', 't1.21', 't1.21.003', '8119']
        self.ps.test_updates['passed'] = False

        # Test steps and verification assertions
        calendar_date = self.teacher.wait.until(
            expect.element_to_be_clickable(
                (By.XPATH, '//div[contains(@class,"Day--upcoming")]')
            )
        )
        self.teacher.driver.execute_script(
            'return arguments[0].scrollIntoView();', calendar_date)
        self.teacher.sleep(1)
        actions = ActionChains(self.teacher.driver)
        actions.move_to_element_with_offset(calendar_date, 50, 10)
        actions.click()
        actions.perform()
        self.teacher.find(
            By.XPATH,
            '//ul[@class="new-assignments"]//a[contains(text(),"Add Event")]'
        ).click()
        assert('event/new' in self.teacher.current_url()),\
            'not at Add Event page'

        self.ps.test_updates['passed'] = True

    # Case C8120 - 004 - Teacher | Set open and due dates for all periods
    # collectively
test_t1_21_CreateAnEvent.py 文件源码 项目:test-automation 作者: openstax 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_teacher_add_an_event_by_dragging_add_event_to_a_cale_111249(self):
        """Add an event by dragging Add Event to a calendar date.

        Steps:
        Click on the 'Add Assignment' menu
        Click and Drag 'Add Event' to a chosen due date

        Expected Result:
        User is taken to 'Add Event' page with the date filled in.
        """
        self.ps.test_updates['name'] = 't1.21.032' \
            + inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates['tags'] = ['t1', 't1.21', 't1.21.032', '111249']
        self.ps.test_updates['passed'] = False

        # Test steps and verification assertions
        raise NotImplementedError(inspect.currentframe().f_code.co_name)
        # Assignment().open_assignment_menu(self.teacher.driver)
        # self.teacher.sleep(1)
        # calendar_date = self.teacher.wait.until(
        #     expect.element_to_be_clickable(
        #         (By.XPATH, '//div[contains(@class,"Day--upcoming")]')
        #     )
        # )
        # add_event = self.teacher.find(
        #     By.XPATH,
        #     '//ul[@class="new-assignments"]//a[contains(text(),"Add Event")]'
        # )
        # actions = ActionChains(self.teacher.driver)
        # actions.drag_and_drop(add_event, calendar_date)
        # actions.perform
        # self.teacher.sleep(4)
        # assert('event/new' in self.teacher.current_url()),\
        #     'not at Add Event Assignment page'
        self.ps.test_updates['passed'] = True
test_t1_18_CreateAnExternalAssignment.py 文件源码 项目:test-automation 作者: openstax 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_teacher_add_external_assignment_using_calendar_date_8086(self):
        """Add an external assignment using the calendar date.

        Steps:
        Click on a calendar date
        Click on the Add External Assignment option

        Expected Result:
        User taken to Add External Assignment page with due date filled in
        """
        self.ps.test_updates['name'] = 't1.18.002' \
            + inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates['tags'] = ['t1', 't1.18', 't1.18.002', '8086']
        self.ps.test_updates['passed'] = False

        # click on calendar date
        calendar_date = self.teacher.wait.until(
            expect.element_to_be_clickable(
                (By.XPATH, '//div[contains(@class,"Day--upcoming")]')
            )
        )
        self.teacher.driver.execute_script(
            'return arguments[0].scrollIntoView();', calendar_date)
        self.teacher.sleep(1)
        actions = ActionChains(self.teacher.driver)
        actions.move_to_element(calendar_date)
        actions.move_by_offset(0, -35)
        actions.click()
        actions.move_by_offset(30, 70)
        actions.click()
        actions.perform()
        assert('external/new' in self.teacher.current_url()),\
            'not at Add External Assignment page'

        self.ps.test_updates['passed'] = True

    # Case C8087 - 003 - Teacher | Set open and due dates for all periods
    # collectively
gmail.py 文件源码 项目:tools 作者: okabe 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def login( self, email, password ):

        self.browser.get( "http://mail.google.com" )
        sleep( 3 )

        self.action = webdriver.ActionChains( self.browser )
        self.email_form = self.browser.find_element_by_id( "Email" )
        self.email_form.send_keys( email )
        self.next_button = self.browser.find_element_by_id( "next" )
        self.next_button.click()
        sleep( 1 )

        if not self.browser.find_element_by_id( "Passwd" ):
            self.printq.put( "[-] Invalid email, removing {} from scope".format( email ) )
            self.emails.remove( email )
        else:
            self.pass_form = self.browser.find_element_by_id( "Passwd" )
            self.pass_form.send_keys( password )
            self.signin_button = self.browser.find_element_by_id( "signIn" )
            self.signin_button.click()
            sleep( 3 )
            self.browser.save_screenshot( "{}_{}.png".format( email, password ) )

            if "Wrong password" in self.browser.page_source:
                self.printq.put( "[!] Login failed: {}:{}".format( email, password ) )
            else:
                self.printq.put( "[^] Login succeeded: {}:{}".format( email, password ) )
qq_login.py 文件源码 项目:python 作者: rookiesmile 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def fuck_verify_code(self):
        Bs = BeautifulSoup(self.browser.page_source,'lxml')
        # print(self.browser.page_source)
        try:
            try:
                Bfind = Bs.find('iframe')['src']    # ??????????url
                self.browser.get(Bfind)
            except TypeError:
                print("?????????????????,??????????????????Sorry~")
        except WebDriverException:
            print("?????????????????,??????????????????Sorry~")
            # self.reboot_verify_code()
        time.sleep(2)
        token_code = self.browser.find_element_by_xpath('//*[@id="token_code"]')
        btn = self.browser.find_element_by_xpath('//*[@id="scroller"]/div[2]/form/div[1]/button')
        verify_code = input("?????: ")    # ?????
        verify_code_action = ActionChains(self.browser)
        verify_code_action.move_to_element(token_code).click().send_keys(verify_code)
        verify_code_action.move_to_element(btn).click()
        verify_code_action.perform()
        time.sleep(5)
        self.browser.save_screenshot('ceshi4.png')
        print("????!,????cookie....")
        cookie = {}
        for c in self.browser.get_cookies():
            cookie[c['name']] = c['value']
        self.sava_cookie(self.username,cookie)
        print("????!")
        uin = self.get_fristdotai_time(self.get_sid(self.browser.page_source))['loginuin']
        qzonetoken = self.get_qzonetoken(self.getCookie(self.username))
        gtk = self.get_gtk(self.getCookie(self.username))
        firstrtime = self.get_fristdotai_time(self.get_sid(self.browser.page_source))['times']
        self.get_dotai_sad(uin,qzonetoken,gtk,firstrtime)
        print("OVER")
    #  ???????
qq_login.py 文件源码 项目:python 作者: rookiesmile 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def login(self):
        print("?????????....")
        u = self.browser.find_element_by_xpath('//*[@id="u"]')
        p = self.browser.find_element_by_xpath('//*[@id="p"]')
        go = self.browser.find_element_by_xpath('//*[@id="go"]')
        u.clear()    # ??????????
        action = ActionChains(self.browser)    # ??????
        action.move_to_element(u).click().send_keys(self.username)   # ??????????????????
        action.move_to_element(p).click().send_keys(self.password)   # ??????????????????
        action.move_by_offset(go.location['x'],go.location['y'])
        action.click(go)
        action.perform()
        time.sleep(3)
        self.browser.save_screenshot('ceshi1.png')
        if self.browser.title != "QQ??":
            print("????~")
            time.sleep(2)
            self.fuck_verify_code()
        else:
            print("????!,????cookie....")
            cookie = {}
            for c in self.browser.get_cookies():
                cookie[c['name']] = c['value']
            self.sava_cookie(self.username,cookie)
            print("????!")
            self.get_dotai_sad(self.get_fristdotai_time(self.get_sid(self.browser.page_source))['loginuin'],self.get_qzonetoken(self.getCookie(self.username)),self.get_gtk(self.getCookie(self.username)),self.get_fristdotai_time(self.get_sid(self.browser.page_source))['times'])
            print("OVER")
webelement.py 文件源码 项目:YOHO_Automated_Test 作者: yzwy1988 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def Set(cls, value):
        if value == "":
            return

        if value == "SET_EMPTY":
            value = ""

        log.step_normal(u"Element [%s]: Set Value [%s]." % (cls.__name__, value))

        # cls.__wait()
        WebDriverWait(env.driver, 10).until(lambda the_driver:
                                            the_driver.find_element(cls.by, cls.value).is_displayed())
        elements = env.driver.find_elements(cls.by, cls.value)

        if elements[cls.index].tag_name == "select" or elements[cls.index].tag_name == "ul":
            cls.Select(value)
            time.sleep(3)

        else:
            elements[cls.index].clear()
            action = webdriver.ActionChains(env.driver)
            action.send_keys_to_element(elements[cls.index], value)
            action.perform()
            time.sleep(3)

            cls.__clearup()
webelement.py 文件源码 项目:YOHO_Automated_Test 作者: yzwy1988 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def movetoelement(cls):
        log.step_normal("Element [%s]: Do movetoelement()" % cls.__name__)

        # cls.__wait()
        WebDriverWait(env.driver, 10).until(lambda the_driver:
                                            the_driver.find_element(cls.by, cls.value).is_displayed())
        element = env.driver.find_element(cls.by, cls.value)

        action = webdriver.ActionChains(env.driver)
        action.move_to_element(element)
        action.perform()
        time.sleep(3)
webelement.py 文件源码 项目:YOHO_Automated_Test 作者: yzwy1988 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def Right_Click(cls):
        log.step_normal("Element [%s]: Do Right_Click()" % cls.__name__)

        # cls.__wait()
        WebDriverWait(env.driver, 10).until(lambda the_driver:
                                            the_driver.find_element(cls.by, cls.value).is_displayed())
        elements = env.driver.find_element(cls.by, cls.value)
        action = webdriver.ActionChains(env.driver)
        action.context_click(elements).perform()
        time.sleep(3)

        cls.__clearup()
webelement.py 文件源码 项目:YOHO_Automated_Test 作者: yzwy1988 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def Click_key_down_up(cls):
        log.step_normal("Element [%s]: Do Click_key_down_up()" % cls.__name__)

        # cls.__wait()
        WebDriverWait(env.driver, 10).until(lambda the_driver:
                                            the_driver.find_element(cls.by, cls.value).is_displayed())
        elements = env.driver.find_element(cls.by, cls.value)

        action = webdriver.ActionChains(env.driver)
        action.key_down(elements).key_up(elements)
        time.sleep(3)

        cls.__clearup()

    # APP?????????????
webelement.py 文件源码 项目:YOHO_Automated_Test 作者: yzwy1988 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def ClickList(cls):
        log.step_normal("Element [%s]: Do ClickList()" % cls.__name__)

        if env.RUNNING_BROWSER in ("Chrome", "Firefox", "IE", "Safari"):
            js1 = "var q = document.documentElement.scrollTop=0"
            env.driver.execute_script(js1)
            time.sleep(3)
            js2 = "var q = document.documentElement.scrollTop=100000"
            env.driver.execute_script(js2)

        # cls.__wait()
        WebDriverWait(env.driver, 10).until(lambda the_driver:
                                            the_driver.find_element(cls.by, cls.value).is_displayed())

        i = 0
        while i < 1:
            elements = env.driver.find_elements(cls.by, cls.value)
            rd = random.randint(0, len(elements)-1)

            action = webdriver.ActionChains(env.driver)
            action.move_to_element(elements[rd])
            action.click(elements[rd])
            action.perform()
            time.sleep(2)

            i += 1

        env.driver.switch_to_window(env.driver.window_handles[-1])
        env.driver.maximize_window()
        time.sleep(3)

        cls.__clearup()
webelement.py 文件源码 项目:YOHO_Automated_Test 作者: yzwy1988 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def ClickAndHold(cls):
        log.step_normal("Element [%s]: Do ClickAndHold()" % cls.__name__)

        # cls.__wait()
        WebDriverWait(env.driver, 10).until(lambda the_driver:
                                            the_driver.find_element(cls.by, cls.value).is_displayed())
        elements = env.driver.find_elements(cls.by, cls.value)

        action = webdriver.ActionChains(env.driver)
        action.move_to_element(elements[cls.index])
        action.click_and_hold(elements[cls.index])
        action.perform()

        cls.__clearup()
webelement.py 文件源码 项目:YOHO_Automated_Test 作者: yzwy1988 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def ReleaseClick(cls):
        log.step_normal("Element [%s]: Do ReleaseClick()" % cls.__name__)

        # cls.__wait()
        WebDriverWait(env.driver, 10).until(lambda the_driver:
                                            the_driver.find_element(cls.by, cls.value).is_displayed())
        elements = env.driver.find_elements(cls.by, cls.value)

        action = webdriver.ActionChains(env.driver)
        action.release(elements[cls.index])
        action.perform()

        cls.__clearup()
webelement.py 文件源码 项目:YOHO_Automated_Test 作者: yzwy1988 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def SendEnter(cls):
        log.step_normal(u"Element [%s]: SendEnter()" % (cls.__name__, ))

        # cls.__wait()
        WebDriverWait(env.driver, 10).until(lambda the_driver:
                                            the_driver.find_element(cls.by, cls.value).is_displayed())
        elements = env.driver.find_elements(cls.by, cls.value)

        action = webdriver.ActionChains(env.driver)
        action.send_keys_to_element(elements[cls.index], Keys.ENTER)
        action.perform()

        cls.__clearup()


问题


面经


文章

微信
公众号

扫码关注公众号