How to use the selenium.webdriver.common.action_chains.ActionChains function in selenium

To help you get started, we’ve selected a few selenium examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github luyishisi / Anti-Anti-Spider / 5.极验验证码资源汇总 / 企业信息查询破解 / basicgeetestcrack.py View on Github external
ActionChains(self.driver).click_and_hold(on_element=element).perform()
        for x, y, t in array_trail:
            ActionChains(self.driver).move_to_element_with_offset(
                to_element=element, 
                xoffset=x+22,
                yoffset=y+22).perform()
            # 这个动作在phantomjs里一定需要,否则 x 是不会移动的,phantomjs成败在此一举(chrome等忽略)
            ActionChains(self.driver).click_and_hold().perform()
            # 可以在调试的时候查看 x 是否有移动,这一点非常重要
            # temp_element = self.driver.find_element_by_class_name(gt_slider_knob_name)
            # print temp_element.location
            time.sleep(t)

        time.sleep(0.4)
        print u'稍等一会儿,搜索结果马上出来...'
        ActionChains(self.driver).release(on_element=element).perform()

        time.sleep(0.5)
        element = self.driver.find_element_by_class_name('gt_info_text')
        status = element.text
        print u"破解验证码的结果: ", status
        # 这个延时必须有,在滑动后等待回复原状
        if not status:
            self.click_refresh()
            return -1
        if status.find(u'失败') > -1:
            self.click_refresh()
            return -1
        if status.find(u'怪物') > -1:
            self.click_refresh(3.4)
            return -1
        wait = WebDriverWait(self.driver, 40, 1.0)
github bokeh / bokeh / tests / integration / interaction / test_tools.py View on Github external
def test_box_select(output_file_url, selenium):
    plot = generate_plot()

    plot.add_tools(BoxSelectTool())

    # Save the plot and start the test
    save(plot)
    selenium.get(output_file_url)
    assert has_no_console_errors(selenium)

    # Drag a box zoom around middle point
    canvas = selenium.find_element_by_tag_name('canvas')

    actions = ActionChains(selenium)
    actions.move_to_element_with_offset(canvas, PLOT_DIM * 0.25, PLOT_DIM * 0.25)
    actions.click_and_hold()
    actions.move_by_offset(PLOT_DIM * 0.5, PLOT_DIM * 0.5)
    actions.release()
    actions.perform()

    # Get the alert from box select and assert that the middle item is selected
    alert = selenium.switch_to_alert()
    assert alert.text == 'middle'
github freeipa / freeipa / ipatests / test_webui / test_netgroup.py View on Github external
# add mixed case netgroup name
        self.add_record(netgroup.ENTITY, netgroup.DATA_MIXED_CASE)
        pkey = netgroup.DATA_MIXED_CASE['pkey'].lower()
        self.delete_record(pkey)

        # add long netgroup name
        self.add_record(netgroup.ENTITY, netgroup.DATA_LONG_NAME, delete=True)

        # add single character netgroup name ticket#2671
        self.add_record(netgroup.ENTITY, netgroup.DATA_SINGLE_CHAR,
                        delete=True)

        # add netgroup using enter
        self.add_record(netgroup.ENTITY, netgroup.DATA, dialog_btn=None)
        actions = ActionChains(self.driver)
        actions.send_keys(Keys.TAB)
        actions.send_keys(Keys.ENTER).perform()
        self.wait_for_request(d=0.5)
        self.assert_record(netgroup.PKEY)
        self.close_notifications()

        # delete netgroup using enter
        self.select_record(netgroup.PKEY)
        self.facet_button_click('remove')
        self.wait_for_request()
        actions = ActionChains(self.driver)
        actions.send_keys(Keys.ENTER).perform()
        self.wait_for_request(d=0.5)
        self.assert_record(netgroup.PKEY, negative=True)
        self.close_all_dialogs()
github mdn / kuma / tests / pages / base.py View on Github external
def show_submenu(self, menu_element, revealed_element,
                         off_element=None):
            """Hover over a menu element that reveals another element.

            For Chrome and local Firefox, it is sufficent to move to the
            element to get a hover.

            For the Remote driver with Firefox, it is more reliable if the
            mouse is first moved off-element, and then on-element. It still
            occasionally fails in some contexts, such as the homepage.
            (geckodriver 0.19.1, Selenium 3.8.1, Firefox 57).
            """
            if off_element is None:
                # Use the logo as the element that isn't the hover menu
                off_element = self.find_element(*self._logo_locator)
            hover = (ActionChains(self.selenium)
                     .move_to_element(off_element)
                     .move_to_element(menu_element))
            hover.perform()
            try:
                self.wait.until(lambda s: revealed_element.is_displayed())
            except TimeoutException:
                if self.selenium._is_remote and self.selenium.name == 'firefox':
                    pytest.xfail("Known issue with hover"
                                 " (Selenium 3 w/ Remote Firefox)")
                raise
github mdn / kuma / tests / pages / article.py View on Github external
def display_language_menu(self):
        submenu_trigger = self.language_menu_button
        submenu = self.find_element(By.ID, 'languages-menu-submenu')
        hover = ActionChains(self.selenium).move_to_element(submenu_trigger)
        hover.perform()
        self.wait.until(lambda s: submenu.is_displayed())
github ManageIQ / integration_tests / pages / regions / policy_menu.py View on Github external
def click_on_manage_policies(self):
        ActionChains(self.selenium).click(self.policy_button).click(
            self.manage_policies_button).perform()
        return PolicyMenu.ManagePolicies(self.testsetup)
github ManageIQ / integration_tests / pages / control_subpages / explorer_subpages / policies.py View on Github external
def remove(self, cancel=False):
        """ Remove this condition

        """
        ActionChains(self.selenium)\
            .click(self.configuration_button)\
            .click(self.configuration_remove_cond_button)\
            .perform()
        self.handle_popup(cancel)
        self._wait_for_results_refresh()
        return PolicyView(self.testsetup)
github weskerfoot / DeleteFB / deletefb / tools / likes.py View on Github external
def unlike_pages(driver):
    """
    Unlike all pages

    Args:
        driver: seleniumrequests.Chrome Driver instance

    Returns:
        None
    """

    like_log, archive_likes = archiver("likes")

    actions = ActionChains(driver)

    load_likes(driver)

    pages_list = driver.find_element_by_css_selector("#all_liked_pages")

    actions.move_to_element(pages_list).perform()

    unlike_buttons = pages_list.find_elements_by_xpath("//button/div/div[text()='Liked']/../..")

    while unlike_buttons:
        for button in unlike_buttons:
            try:
                if "Liked" in button.text:
                    page_name = button.find_element_by_xpath("./../..").text.split("\n")[0]

                    driver.execute_script("arguments[0].click();", button)
github ForgQi / bilibiliupload / engine / slider / __init__.py View on Github external
def move_to_gap(self, slider, track):
        """
        拖动滑块到缺口处
        :param slider: 滑块
        :param track: 轨迹
        :return:
        """
        ActionChains(self.driver).click_and_hold(slider).perform()
        for x in track:
            ActionChains(self.driver).move_by_offset(xoffset=x, yoffset=random.uniform(-5, 2)).perform()
        time.sleep(0.5)
        ActionChains(self.driver).release().perform()
github elliterate / capybara.py / capybara / selenium / node.py View on Github external
def hover(self):
        ActionChains(self.driver.browser).move_to_element(self.native).perform()