当前位置: 首页>>代码示例>>Python>>正文


Python ActionChains.move_by_offset方法代码示例

本文整理汇总了Python中selenium.webdriver.ActionChains.move_by_offset方法的典型用法代码示例。如果您正苦于以下问题:Python ActionChains.move_by_offset方法的具体用法?Python ActionChains.move_by_offset怎么用?Python ActionChains.move_by_offset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在selenium.webdriver.ActionChains的用法示例。


在下文中一共展示了ActionChains.move_by_offset方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: drag

# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import move_by_offset [as 别名]
 def drag(self, x_offset, y_offset):
     center = self.driver.execute_script(GetScripts.getContainerCenter)
     actions = ActionChains(self.driver)
     actions.move_to_element_with_offset(self.element, int(center['x']), int(center['y']))
     actions.click_and_hold()
     actions.move_by_offset(x_offset, y_offset)
     actions.release().perform()
开发者ID:2gis,项目名称:mapsapi,代码行数:9,代码来源:map.py

示例2: zoom_selection

# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import move_by_offset [as 别名]
 def zoom_selection(self):
     center = self.driver.execute_script(GetScripts.getContainerCenter)
     actions = ActionChains(self.driver)
     actions.move_to_element_with_offset(self.element, int(center['x']), int(center['y']))
     actions.key_down(Keys.SHIFT)
     actions.click_and_hold()
     actions.move_by_offset(300, 300)
     actions.release()
     actions.perform()
开发者ID:2gis,项目名称:mapsapi,代码行数:11,代码来源:map.py

示例3: answer_problem

# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import move_by_offset [as 别名]
    def answer_problem(self, correctness):
        """
        Answer image problem.
        """
        offset = 25 if correctness == 'correct' else -25
        input_selector = ".imageinput [id^='imageinput_'] img"
        input_element = self.problem_page.q(css=input_selector)[0]

        chain = ActionChains(self.browser)
        chain.move_to_element(input_element)
        chain.move_by_offset(offset, offset)
        chain.click()
        chain.perform()
开发者ID:shevious,项目名称:edx-platform,代码行数:15,代码来源:test_problem_types.py

示例4: action_elements_events

# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import move_by_offset [as 别名]
def action_elements_events(self, element_menu, drag_divs):
    action = ActionChains(self.driver)
    action.move_to_element(element_menu).click(element_menu)
    action.click_and_hold(drag_divs)
    action.move_by_offset(35, 35)
    action.move_by_offset(15, 20)
    action.move_by_offset(55, 15)
    action.release()
    action.perform()
    event_start = self.driver.find_element_by_xpath("//li[@id = 'event-start']/span[2]").text
    event_drag = self.driver.find_element_by_xpath("//li[@id='event-drag']/span[2]").text
    event_stop = self.driver.find_element_by_xpath("//li[@id = 'event-stop']/span[2]").text
    return event_start, event_drag, event_stop
开发者ID:slav1k,项目名称:demoqa_com_python,代码行数:15,代码来源:DemoqaComDraggable.py

示例5: move_slider

# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import move_by_offset [as 别名]
 def move_slider(self, slider, offset=0.0):
     """Click somewhere in an horizontal slider. The position is given in fraction
        of its width: *offset* from 0 to 1."""
     width = slider.size['width']
     action_chains = ActionChains(self.driver)
     # Move to the middle of the slider (default), then to its leftmost point
     action_chains.move_to_element(slider).move_by_offset(-width/2.0, 0)
     # Double-click twice to know where the cursor is.
     #action_chains.context_click().context_click()
     # Need to perform() because it seems to bug with move_by_offset otherwise
     action_chains.perform()
     # Offset to the right
     action_chains.move_by_offset(width * offset, 0)
     # Double-click twice to know where the cursor is
     #action_chains.context_click().context_click()
     action_chains.click().perform()
开发者ID:a113n,项目名称:varapp-backend-py,代码行数:18,代码来源:test_2_filters.py

示例6: add_object_to_workflow

# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import move_by_offset [as 别名]
 def add_object_to_workflow(self, obj_path, target_name):
     """ Add `obj_path` object to `target_name` in workflow. """
     for retry in range(3):
         try:
             obj = self.find_object_button(obj_path)
             target = self.get_workflow_figure(target_name)
             chain = ActionChains(self.browser)
             chain.move_to_element(obj)
             chain.click_and_hold(obj)
             chain.move_to_element(target.root)
             chain.move_by_offset(2, 1)
             chain.release(None)
             chain.perform()
         except StaleElementReferenceException:
             if retry < 2:
                 logging.warning("add_object_to_workflow:" " StaleElementReferenceException")
             else:
                 raise
         else:
             break
开发者ID:RacerXFD,项目名称:OpenMDAO-Framework,代码行数:22,代码来源:workspace.py

示例7: test_remove_tag

# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import move_by_offset [as 别名]
    def test_remove_tag(self):
        old_tag_num = len(self.browser.find_by_css('span.taggit_tag'))
        
        driver = self.browser.driver
        actions = ActionChains(driver)
        tag_link = driver.find_element_by_css_selector('#taggit_tags a')
        actions.move_to_element(tag_link)
        actions.move_by_offset(25, 10)
        actions.click()
        actions.perform()
        
        document_list_url = \
            self.live_server_url + reverse('documents.views.list_documents')
        self.assertEquals(self.browser.url, document_list_url)
        
        new_tag_num = len(self.browser.find_by_css('span.taggit_tag'))
        self.assertEquals(new_tag_num, old_tag_num - 1)
        
#        import time; time.sleep(3)
        self.browser.quit()
开发者ID:CulturePlex,项目名称:festos,代码行数:22,代码来源:test_tag.py

示例8: test_teacher_report_errata_about_assessments_in_cc_14858

# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import move_by_offset [as 别名]
    def test_teacher_report_errata_about_assessments_in_cc_14858(self):
        """Report errata about assessments in Concept Coach.

        Steps:
        If the user has more than one course, click on a CC course name
        Click "Question Library" from the user menu
        Select a section or chapter
        Click "Show Questions"
        Hover over the desired question and click "Question details"
        Click "Report an error"

        Expected Result:
        A new tab with the assessment errata form appears, with the assessment
        ID already filled in
        """
        self.ps.test_updates['name'] = 'cc2.11.005' \
            + inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates['tags'] = ['cc2', 'cc2.11', 'cc2.11.005', '14858']
        self.ps.test_updates['passed'] = False

        # Test steps and verification assertions
        self.teacher.login()
        self.teacher.find(
            By.XPATH, '//a[contains(@href,"/cc-dashboard")]'
        ).click()
        self.teacher.open_user_menu()
        self.teacher.find(
            By.LINK_TEXT, 'Question Library'
        ).click()
        self.teacher.find(
            By.XPATH,
            '//div[@class="section"]//span[@class="chapter-section" ' +
            'and @data-chapter-section="1.2"]'
        ).click()
        self.teacher.driver.execute_script(
            "window.scrollTo(0, document.body.scrollHeight);")
        self.teacher.find(
            By.XPATH, '//button[text()="Show Questions"]'
        ).click()
        self.teacher.wait.until(
            expect.visibility_of_element_located(
                (By.XPATH, '//div[@class="exercises"]')
            )
        )
        self.teacher.sleep(1)
        question = self.teacher.find(
            By.XPATH, '//div[@class="exercises"]/div[1]'
        )
        actions = ActionChains(self.teacher.driver)
        actions.move_to_element(question)
        # way to stall because not sure how to add wait in action chain
        for _ in range(50):
            actions.move_by_offset(1, 0)
        actions.click()
        actions.perform()
        self.teacher.sleep(0.5)
        exercise_id = self.teacher.wait.until(
            expect.visibility_of_element_located(
                (By.XPATH,
                 '//span[@class="exercise-tag" and contains(text(),"ID:")]')
            )
        ).text
        question = self.teacher.find(
            By.XPATH, '//div[@class="action report-error"]'
        ).click()
        window_with_form = self.teacher.driver.window_handles[1]
        self.teacher.driver.switch_to_window(window_with_form)
        self.teacher.wait.until(
            expect.visibility_of_element_located(
                (By.XPATH, '//div[text()="Report Content Errors"]')
            )
        )
        self.teacher.find(
            By.XPATH, '//input[@value="' + exercise_id[4:] + '"]')

        self.ps.test_updates['passed'] = True
开发者ID:openstax,项目名称:test-automation,代码行数:78,代码来源:test_cc2_11_ImproveQuestionManagement.py

示例9: test_teacher_exclude_certain_questions_14852

# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import move_by_offset [as 别名]
    def test_teacher_exclude_certain_questions_14852(self):
        """Exclude certain quesitons.

        Steps:
        If the user has more than one course, click on a CC course name
        Click "Question Library" from the user menu
        Select a section or chapter
        Click "Show Questions"
        Hover over the desired question and click "Exclude question"

        Expected Result:
        Question is grayed out
        """
        self.ps.test_updates['name'] = 'cc2.11.002' \
            + inspect.currentframe().f_code.co_name[4:]
        self.ps.test_updates['tags'] = ['cc2', 'cc2.11', 'cc2.11.002', '14852']
        self.ps.test_updates['passed'] = False

        # Test steps and verification assertions
        self.teacher.login()
        self.teacher.find(
            By.XPATH, '//a[contains(@href,"/cc-dashboard")]'
        ).click()
        self.teacher.open_user_menu()
        self.teacher.find(
            By.LINK_TEXT, 'Question Library'
        ).click()
        self.teacher.find(
            By.XPATH,
            '//div[@class="section"]//span[@class="chapter-section" ' +
            'and @data-chapter-section="1.2"]'
        ).click()
        self.teacher.driver.execute_script(
            "window.scrollTo(0, document.body.scrollHeight);")
        self.teacher.find(
            By.XPATH, '//button[text()="Show Questions"]'
        ).click()
        self.teacher.wait.until(
            expect.visibility_of_element_located(
                (By.XPATH, '//div[@class="exercises"]')
            )
        )
        self.teacher.sleep(1)
        i = 1
        question = None
        # loop finding a question that is not yet excleded
        # there are 9 question in the exact textbook and chpater this test
        # is searching. limiting loop at 7 incase questions are removed.
        while i < 8:
            question = self.teacher.find(
                By.XPATH,
                '//div[@class="exercises"]/div[' + str(i) + ']'
            )
            if ('is-selected' not in question.get_attribute('class')):
                break
            i += 1
        Assignment.scroll_to(self.teacher.driver, question)
        self.teacher.sleep(1)
        actions = ActionChains(self.teacher.driver)
        actions.move_to_element(question)
        # way to stall because not sure how to add wait in action chain
        for _ in range(50):
            actions.move_by_offset(-1, 0)
        actions.click()
        actions.move_by_offset(-50, -300)
        actions.perform()
        self.teacher.sleep(0.5)
        question_excluded = self.teacher.find(
            By.XPATH, '//div[@class="exercises"]/div[' + str(i) + ']'
        ).get_attribute('class')
        assert('is-selected' in question_excluded), 'question not excluded'
        self.ps.test_updates['passed'] = True
开发者ID:openstax,项目名称:test-automation,代码行数:74,代码来源:test_cc2_11_ImproveQuestionManagement.py

示例10: resize_editor

# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import move_by_offset [as 别名]
    def resize_editor(self, editor):
        '''ensure that the editor is not covering the library
        (or else we cannot drag things from it!)'''
        browser = self.browser

        page_width = browser.get_window_size()['width']

        lib_tab      = self('library_tab').find_element_by_xpath('..')
        lib_width    = lib_tab.size['width']
        lib_position = lib_tab.location['x']

        dialog_title    = editor('dialog_title').find_element_by_xpath('../..')
        dialog_width    = dialog_title.size['width']
        dialog_position = dialog_title.location['x']

        # how much overlap do we have?
        overlap = lib_position - (dialog_position + dialog_width)

        if overlap < 0:  # we are overlapping
            # check to see if we have enough room to move out of the way
            if page_width < dialog_width + lib_width:
                # not enough, need to rezize the editor

                # look for the resize handle
                sibblings = dialog_title.find_elements_by_xpath('../../div')
                handle = None
                for sib in sibblings:
                    if "ui-resizable-se" in sib.get_attribute('class'):
                        handle = sib

                # do the resizing
                chain = ActionChains(browser)
                chain.click_and_hold(handle)
                # we can resize editor down to 425px, any less and we cover drop targets
                chain.move_by_offset(450 - dialog_width, 0).perform()
                # must click because release is not working. why? I do not know.
                chain.click().perform()
                chain.release(None).perform()

                # recalculate the overlap
                dialog_title = editor('dialog_title').find_element_by_xpath('../..')
                dialog_width = dialog_title.size['width']
                dialog_position = dialog_title.location['x']
                overlap = lib_position - (dialog_position + dialog_width)

            # We are good, move out!
            chain = ActionChains(browser)
            chain.click_and_hold(editor('dialog_title').element)
            chain.move_by_offset(overlap, 0).perform()
            # must click because release is not working. why? I do not know.
            chain.click().perform()
            chain.release(None).perform()

            # recalculate the overlap
            dialog_title = editor('dialog_title').find_element_by_xpath('../..')
            dialog_width = dialog_title.size['width']
            dialog_position = dialog_title.location['x']
            overlap = lib_position - (dialog_position + dialog_width)

            if overlap < 0:
                # we still have a problem.
                eq(True, False,
                    "Could not move or rezise the editor dialog so it is not "
                    "overlapping the library. The browser window is too small")
开发者ID:Daiyu506,项目名称:OpenMDAO-Framework,代码行数:66,代码来源:workspace.py

示例11: move_to_element

# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import move_by_offset [as 别名]
 def move_to_element(self, ele):
     action = ActionChains(self.driver)
     action.move_to_element(ele)
     action.move_by_offset(1, 1)
     action.perform()
开发者ID:LegendZhu,项目名称:AutomationFrameWork,代码行数:7,代码来源:abstract_base_page.py

示例12: retriveRatings

# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import move_by_offset [as 别名]
def retriveRatings(browser,mainWind,url):
    browser.driver.get(url)
    windows=browser.driver.window_handles
    for wind in windows:
        if wind!=mainWind:
            browser.driver.switch_to_window(wind)
            browser.driver.close()

    browser.driver.switch_to_window(mainWind)

    # Azioni per andare a chiudere il popup nel caso apparisse
    actions = ActionChains(browser.driver)
    actions.move_by_offset(40,50).click()
    actions.perform()

    # Filtraggio dei Rates per RATINGS e ATTRAZIONI
    try:
        ratesFilter=browser.wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "ul.cs-contribution-bar > li[data-filter='RATINGS_ALL'] > a")))
        ratesFilter.click()

    except TimeoutException:
        print "\n\nNon e presente il filtro per RATINGS!"
        return
    try:
        dataFilter=browser.wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "div.cs-filter-bar ul > li[data-filter='RATINGS_ATTRACTIONS']")))
        dataFilter.click()
    except TimeoutException:
        print "\n\nNon e presente il filtro per ATTRACTIONS!"
        return

    # Recupero dei dati dei vari RATES
    nextPage,globDates,globLocations,globAttractions,globRates=True,[],[],[],[]
    while nextPage:
        try:
            dates=browser.wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, "div.cs-rating-date")))
            locations=browser.wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, "div.cs-rating-geo")))
            attractions=browser.wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, "div.cs-rating-location a")))
            rates=browser.wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, "div.cs-rating img")))

            dates=[date.text for date in dates]
            locations=[loc.text for loc in locations]
            attractions=[attr.text for attr in attractions]
            rates=[rate.get_attribute("content") for rate in rates]

            print "\n\nATTRAZIONI: {}\n\nLOCATIONS: {}\n\nRATES: {}\n\nDATES: {}".format(attractions,locations,rates,dates)
            globDates.extend(dates)
            globLocations.extend(locations)
            globAttractions.extend(attractions)
            globRates.extend(rates)

        except TimeoutException:
            print "\nTempo Terminato! Elementi non trovati"
        try:
            nextPage=browser.wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#cs-paginate-next")))
            actions=ActionChains(browser.driver)
            actions.click(nextPage)
            actions.perform()

        except WebDriverException:
            print "\nNEXT non presente!"
            nextPage=None

    return zip(globDates,globLocations,globAttractions,globRates)
开发者ID:drugotosto,项目名称:WebScraping,代码行数:65,代码来源:vario.py

示例13: sleep

# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import move_by_offset [as 别名]
sleep(1)

driver.find_element_by_id("remove_action").click()
driver.switch_to_alert().accept()
if driver.execute_script("return program.actions.length") == 0:
    print("Successful: Action deleted")
else:
    print("Failure: Action deleted")

sleep(1)

actions.move_to_element(canvas).perform()
sleep(1)

actions = ActionChains(driver)
actions.move_by_offset(0, -16)
actions.click()
actions.perform()

sleep(1)

actions = ActionChains(driver)
actions.move_to_element(canvas)
actions.click()
actions.perform()

sleep(1)

driver.find_element_by_id("name").send_keys("b")
driver.find_element_by_id("script").send_keys("print('hello world')")
driver.find_element_by_id("agent-edit").click()
开发者ID:seanlth,项目名称:CS4098PaddyPaddy,代码行数:33,代码来源:test.py

示例14: Login

# 需要导入模块: from selenium.webdriver import ActionChains [as 别名]
# 或者: from selenium.webdriver.ActionChains import move_by_offset [as 别名]

#.........这里部分代码省略.........
        return rangle

    def image(self,rangle):
        screenshot=self.browser.get_screenshot_as_png()
        screenshot=Image.open(BytesIO(screenshot))
        captche=screenshot.crop(rangle)
        return captche

    def get_image1(self):
        rangle=self.get_position1()
        time.sleep(2)
        captche=self.image(rangle)
        width=captche.size[0]
        height=captche.size[1]
        #captche = captche.resize((int(width*0.8), int(height*0.8)),Image.ANTIALIAS)
        captche.save('a.png')
        return captche

    def get_image2(self):
        rangle=self.get_position2()
        time.sleep(3)
        captche=self.image(rangle)
        width=captche.size[0]
        height=captche.size[1]
        #captche = captche.resize((int(width*0.8), int(height*0.8)),Image.ANTIALIAS)
        captche.save('b.png')
        return captche

    def is_pixel_equal(self, image1, image2, x, y):
        #判断两个像素是否相同
        pixel1=image1.load()[x,y]
        pixel2=image2.load()[x,y]
        a=pixel1[0]-pixel2[0]
        b=pixel1[1]-pixel2[2]
        c=pixel1[2]-pixel2[2]
        threshold=60
        if abs(a)<threshold and abs(b)<threshold and abs(c)<threshold:
            return True
        else:
            return False

    def get_gap(self, image1, image2):
        #获得缺口
        left=60    #滑片宽度
        for i in range(left, image1.size[0]):
            for j in range(image1.size[1]):
                if not self.is_pixel_equal(image1, image2, i, j):
                    left = i
                    return left
        return left

    def get_track(self,distance):
        #获得滑块的运动轨迹
        track=[]
        current=0
        v=0
        t=0.2
        m=distance*0.35
        n=distance*0.7
        while current<distance:
            if current<n:
                a=4
            else:
                a=-6
            v0=v
            v=v0+a*t
            move=v0*t+0.5*a*t*t
            current+=move
            track.append(round(move))
        return track

    def move_to_grap(self):
        image1=self.get_image1()
        image2=self.get_image2()
        success=self.browser.find_element(By.CLASS_NAME,'geetest_success_radar_tip_content')
        slider=self.browser.find_element(By.CLASS_NAME,'geetest_slider_button')
        button=self.browser.find_element(By.CLASS_NAME,'ivu-btn')
        # +20多向前移动20的距离
        distance=(self.get_gap(image1,image2)-6)+20
        print(distance)
        track=self.get_track(distance)
        print(track)
        back_tracks=[-3,-3,-2,-2,-2,-2,-2,-1,-1,-1,-1]     #待会回移的轨迹段
        # while success.text!='验证成功':
        # for i in range(0,2):
        self.action.click_and_hold(slider)
        for x in track:
           self.action.move_by_offset(xoffset=x,yoffset=0)
        time.sleep(0.5)
        for y in back_tracks:
            self.action.move_by_offset(xoffset=y,yoffset=0)
        self.action.move_by_offset(xoffset=-3,yoffset=0)         #小范围震荡
        self.action.move_by_offset(xoffset=3,yoffset=0)
        time.sleep(0.5)
        self.action.release(slider)
        self.action.perform()
        time.sleep(2)
        # print(success.text)
        # if success.text=='验证成功':
        self.action.click(button).perform()
开发者ID:mo-nian,项目名称:learngit,代码行数:104,代码来源:captcha.py


注:本文中的selenium.webdriver.ActionChains.move_by_offset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。