Python selenium.webdriver.common.action_chains.ActionChains() Examples

The following are 30 code examples of selenium.webdriver.common.action_chains.ActionChains(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module selenium.webdriver.common.action_chains , or try the search function .
Example #1
Source File: Fic.py    From RENAT with Apache License 2.0 7 votes vote down vote up
def click_on(self,point,element=u'//canvas',mark_screen=False):
        """ Click on a screen coordinate of an element

        Default element is `//cannvas`
        """
        x,y = point
        el = self._selenium.get_webelement(element)
        action = ActionChains(self._selenium.driver)
        action.move_to_element_with_offset(el,0,0).perform()
        action.move_to_element_with_offset(el,x,y).perform()
        if mark_screen:
            BuiltIn().log("Marked to screen on (%d,%d)" % (x,y))
            img_file = self.capture_screenshot(extra='_click')
            img = cv2.imread(Common.get_result_path() + '/' + img_file)
            cv2.drawMarker(img, (int(x),int(y)), color=(0,255,0), markerType=cv2.MARKER_CROSS, thickness=2)
            cv2.imwrite(Common.get_result_path() + '/' + img_file,img)
        action.click().perform()
        self.wait_until_loaded()
        BuiltIn().log("Clicked on element %s at (%d,%d)" % (element,x,y)) 
Example #2
Source File: test_molecule3d.py    From dash-bio with MIT License 7 votes vote down vote up
def test_dbm3002_rotate(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div([
        dash_bio.Molecule3dViewer(
            id=_COMPONENT_ID,
            modelData=_model_data,
            styles=_styles_data
        )
    ])

    dash_duo.start_server(app)
    dash_duo.wait_for_element('#' + _COMPONENT_ID)

    mol3d = dash_duo.find_element('#' + _COMPONENT_ID + ' canvas')
    ac = ActionChains(dash_duo.driver)
    ac.drag_and_drop_by_offset(mol3d, 100, 50).perform()

    dash_duo.percy_snapshot('test-mol3d_rotate') 
Example #3
Source File: element.py    From nerodia with MIT License 6 votes vote down vote up
def drag_and_drop_on(self, other):
        """
        Drag and drop this element on to another element instance
        Note that browser support may vary

        :param other: element to drop on

        :Example: Drag an element onto another

        a = browser.div(id='draggable')
        b = browser.div(id='droppable')
        a.drag_and_drop_on(b)
        """
        self._assert_is_element(other)

        value = self._element_call(lambda: ActionChains(self.driver)
                                   .drag_and_drop(self.el, other.wd).perform(),
                                   self.wait_for_present)
        self.browser.after_hooks.run()
        return value 
Example #4
Source File: test_speck.py    From dash-bio with MIT License 6 votes vote down vote up
def test_dbsp002_click_and_drag(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div(
        dash_bio.Speck(
            id=_COMPONENT_ID,
            data=_data
        )
    )

    dash_duo.start_server(app)
    dash_duo.wait_for_element('#' + _COMPONENT_ID)

    speck = dash_duo.find_element('#' + _COMPONENT_ID + ' canvas')
    ac = ActionChains(dash_duo.driver)
    ac.move_to_element(speck).key_down(Keys.SHIFT).drag_and_drop_by_offset(
        speck, -50, 100).key_up(Keys.SHIFT).perform()

    dash_duo.percy_snapshot('test-speck_click_and_drag') 
Example #5
Source File: test_speck.py    From dash-bio with MIT License 6 votes vote down vote up
def test_dbsp001_rotate(dash_duo):

    app = dash.Dash(__name__)

    app.layout = html.Div(
        dash_bio.Speck(
            id=_COMPONENT_ID,
            data=_data
        )
    )

    dash_duo.start_server(app)
    dash_duo.wait_for_element('#' + _COMPONENT_ID)

    speck = dash_duo.find_element('#' + _COMPONENT_ID + ' canvas')
    ac = ActionChains(dash_duo.driver)
    ac.move_to_element(speck).drag_and_drop_by_offset(
        speck, 150, 200).perform()

    dash_duo.percy_snapshot('test-speck_rotate') 
Example #6
Source File: lf2environment.py    From lf2gym with MIT License 6 votes vote down vote up
def perform_actions_3(self, actions, delay=0, pause=True):
        action_chains = ActionChains(self.driver)

        for key, flag in self.dir_keys.items():
            if flag:
                if key not in actions:
                    self.keyup(key)
            else:
                if key in actions:
                    self.keydown(key)

        if pause:
            action_chains.send_keys(Keys.F2)
            for _ in range(delay):
                action_chains.send_keys(Keys.F2)

        action_chains.perform() 
Example #7
Source File: lf2environment.py    From lf2gym with MIT License 6 votes vote down vote up
def perform_actions_3_2(self, actions, delay=0, pause=True):
        action_chains = ActionChains(self.driver)

        for key, flag in self.dir_keys_2.items():
            if flag:
                if key not in actions:
                    self.keyup_2(key)
            else:
                if key in actions:
                    self.keydown_2(key)

        if pause:
            action_chains.send_keys(Keys.F2)
            for _ in range(delay):
                action_chains.send_keys(Keys.F2)

        action_chains.perform() 
Example #8
Source File: make_noise.py    From ScatterFly with GNU Affero General Public License v3.0 6 votes vote down vote up
def random_youtube():
    iterations = randint(1,8)
    count = 0
    while(1):
        item = words[randint(0,len(words))]
        driver.get("https://www.youtube.com/results?search_query="+item)
        element = driver.find_element_by_class_name('yt-uix-tile-link')
        element.click()
        actions = ActionChains(driver)
        actions.send_keys('K')
        actions.perform()
        time.sleep(randint(15,50))
        print("currently on site: " + driver.current_url)
        count = count +1
        if count == iterations:
            break; 
Example #9
Source File: driver.py    From behave-webdriver with MIT License 6 votes vote down vote up
def move_to_element(self, element, offset=None):
        """
        Moves the mouse to the middle of an element

        :param element: CSS Selector or XPATH used to locate the element
        :type element: str
        :param offset: optional tuple of x/y offsets to offset mouse from center
        :type offset: tuple
        :return:
        """
        elem = self.get_element(element)
        actions = ActionChains(self)
        if offset:
            actions.move_to_element_with_offset(elem, *offset)
        else:
            actions.move_to_element(elem)
        actions.perform() 
Example #10
Source File: whatsapp.py    From Simple-Yet-Hackable-WhatsApp-api with Apache License 2.0 6 votes vote down vote up
def clear_chat(self, name):
        self.browser.find_element_by_css_selector("._3FRCZ").send_keys(name+Keys.ENTER)
        menu_xpath = "/html/body/div[1]/div/div/div[4]/div/header/div[3]/div/div[3]/div/span"
        WebDriverWait(self.browser, self.timeout).until(EC.presence_of_element_located(
                (By.XPATH, menu_xpath)))
        menu = self.browser.find_element_by_xpath(menu_xpath)
        menu.click()
        chains = ActionChains(self.browser)
        for i in range(4):
            chains.send_keys(Keys.ARROW_DOWN)
        chains.send_keys(Keys.ENTER)
        chains.perform()
        clear_xpath = '//*[@id="app"]/div/span[2]/div/div/div/div/div/div/div[2]/div[2]'
        WebDriverWait(self.browser, self.timeout).until(EC.presence_of_element_located(
                (By.XPATH, clear_xpath)))
        self.browser.find_element_by_xpath(clear_xpath).click()



    # override the timeout 
Example #11
Source File: tb_login.py    From TB-Crawler with MIT License 6 votes vote down vote up
def _move_simulation(device, e):
    try:
        action = ActionChains(device)
        action.click_and_hold(e).perform()
        # action.reset_actions()
        offset = 21
        for i in range(210 / offset):
            ActionChains(device).move_by_offset(xoffset=offset, yoffset=0).perform()
            time.sleep((offset - i) / 50)
        action.release().perform()
        action.reset_actions()
    except Exception as e:
        if DEBUG: print e


# 模拟输入 
Example #12
Source File: test_ui.py    From todoism with MIT License 6 votes vote down vote up
def test_edit_item(self):
        self.login()
        time.sleep(1)

        try:
            item = self.client.find_element_by_xpath("//span[text()='test item 1']")
            item_body = 'test item 1'
        except NoSuchElementException:
            item = self.client.find_element_by_xpath("//span[text()='test item 2']")
            item_body = 'test item 2'

        hover_item = ActionChains(self.client).move_to_element(item)
        hover_item.perform()
        edit_button = self.client.find_element_by_class_name('edit-btn')
        edit_button.click()
        edit_item_input = self.client.find_element_by_id('edit-item-input')
        edit_item_input.send_keys(' edited')
        edit_item_input.send_keys(Keys.RETURN)
        time.sleep(1)
        self.assertIn('%s edited' % item_body, self.client.page_source) 
Example #13
Source File: conversations.py    From DeleteFB with MIT License 6 votes vote down vote up
def delete_conversation(driver, convo):
    """
    Deletes a conversation
    """

    actions = ActionChains(driver)

    menu_select = Select(driver.find_element_by_xpath("//select/option[contains(text(), 'Delete')]/.."))

    for i, option in enumerate(menu_select.options):
        if option.text.strip() == "Delete":
            menu_select.select_by_index(i)
            break

    wait_xpath(driver, "//h2[contains(text(), 'Delete conversation')]")
    delete_button = driver.find_element_by_xpath("//a[contains(text(), 'Delete')][@role='button']")
    actions.move_to_element(delete_button).click().perform()

    return 
Example #14
Source File: Fic.py    From RENAT with Apache License 2.0 6 votes vote down vote up
def shake(self):
        """ Simulates a shake of the screen

        By shaking, the current topology information will be updated in
        browser's localstorage
        """
        # shake the screen once to update localstorage
        action = ActionChains(self._selenium.driver)
        element = self._selenium.get_webelement('//body')
        action.move_to_element_with_offset(element,0, 0).perform()
        action.move_to_element_with_offset(element,200,200).perform()
        action.click_and_hold(element).perform()
        action.move_by_offset(1,0).perform()
        action.move_by_offset(-1,0).perform()
        action.release().perform()
        self.refresh_canvas()
        BuiltIn().log("Shaked the canvas once") 
Example #15
Source File: base.py    From tir with MIT License 6 votes vote down vote up
def move_to_element(self, element):
        """
        [Internal]

        Move focus to element on the screen.

        :param element: Selenium element
        :type element: Selenium object

        Usage:

        >>> #Defining an element:
        >>> element = lambda: self.driver.find_element_by_id("example_id")
        >>> #Calling the method
        >>> self.scroll_to_element(element())
        """
        ActionChains(self.driver).move_to_element(element).perform() 
Example #16
Source File: QQtoWY.py    From syncPlaylist with MIT License 6 votes vote down vote up
def prepare(self):
        self.browser.get("http://music.163.com")
        # self.browser.set_window_size(1920, 1080)
        action = action_chains.ActionChains(self.browser)
        action.send_keys()
        self.browser.switch_to.frame("contentFrame")
        self.browser.execute_script("document.getElementById('index-enter-default').click()")
        self.browser.switch_to.default_content()
        sleep(0.5)
        self.browser.execute_script("document.querySelectorAll('[data-type=\"netease\"]')[0].click()")
        sleep(0.5)
        element = self.browser.find_element_by_css_selector('input[class="js-input u-txt"]')
        element.send_keys(self.config.account)
        sleep(0.5)
        element = self.browser.find_element_by_css_selector('input[type=\"password\"]')
        element.send_keys(self.config.password)
        sleep(0.5)
        self.browser.execute_script("document.querySelectorAll('[data-action=\"login\"]')[6].click()")
        print("login sucess") 
Example #17
Source File: testvideo.py    From netflix-proxy with MIT License 5 votes vote down vote up
def enablePlayerDiagnostics(self):
        actions = ActionChains(self.driver)
        actions.key_down(Keys.CONTROL).key_down(Keys.ALT).key_down(Keys.SHIFT).send_keys('d').perform() 
Example #18
Source File: element.py    From nerodia with MIT License 5 votes vote down vote up
def click(self, *modifiers):
        """
        Clicks the element, optionally while pressing the given modifier keys.
        Note that support for holding a modifier key is currently experimental, and may not work
        at all.

        :param modifiers: modifier keys to press while clicking
        :Example: Click an element

        browser.element(name='new_user_button').click()

        :Example: Click an element with shift key pressed
        from selenium.webdriver.common.keys import Keys
        browser.element(name='new_user_button').click(Keys.SHIFT)

        :Example: Click an element with several modifier keys pressed
        from selenium.webdriver.common.keys import Keys
        browser.element(name='new_user_button').click(Keys.SHIFT, Keys.CONTROL)
        """

        def method():
            if modifiers:
                action = ActionChains(self.driver)
                for mod in modifiers:
                    action.key_down(mod)
                action.click(self.el)
                for mod in modifiers:
                    action.key_up(mod)
                action.perform()
            else:
                self.el.click()

        self._element_call(method, self.wait_for_enabled)
        self.browser.after_hooks.run() 
Example #19
Source File: extended_webelement.py    From golem with MIT License 5 votes vote down vote up
def mouse_over(self):
        """Mouse over element"""
        action_chains = ActionChains(self.parent)
        action_chains.move_to_element(self).perform() 
Example #20
Source File: extended_webelement.py    From golem with MIT License 5 votes vote down vote up
def double_click(self):
        """Double click the element"""
        action_chains = ActionChains(self.parent)
        action_chains.double_click(self).perform() 
Example #21
Source File: chat.py    From whatsapp-web with MIT License 5 votes vote down vote up
def sendMsg(driver, msg):
        """
        Type 'msg' in 'driver' and press RETURN
        """
        # select correct input box to type msg
        input_box = driver.find_element(By.XPATH, '//*[@id="main"]//footer//div[contains(@contenteditable, "true")]')
        # input_box.clear()
        input_box.click()

        action = ActionChains(driver)
        action.send_keys(msg)
        action.send_keys(Keys.RETURN)
        action.perform() 
Example #22
Source File: harvest_utils.py    From DLink_Harvester with GNU General Public License v3.0 5 votes vote down vote up
def mouseClick(css:str):
    global driver
    actions = ActionChains(driver)
    el = waitElem(css)
    actions.move_to_element(el).click().perform() 
Example #23
Source File: lf2environment.py    From lf2gym with MIT License 5 votes vote down vote up
def perform_actions(self, actions, delay=0, pause=True):
        action_chains = ActionChains(self.driver)
        if pause:
            action_chains.key_down(Keys.F2)
        for action in actions:
            action_chains.key_down(action)
        if pause:
            for _ in range(delay):
                action_chains.key_down(Keys.F2)
        action_chains.perform() 
Example #24
Source File: helpers.py    From winnaker with MIT License 5 votes vote down vote up
def move_to_element(driver, e, click=False):
    from selenium.webdriver.common.action_chains import ActionChains
    actions = ActionChains(driver)
    if click:
        actions.move_to_element(e).click().perform()
    else:
        actions.move_to_element(e).perform() 
Example #25
Source File: testvideo.py    From netflix-proxy with MIT License 5 votes vote down vote up
def enablePlayerControls(self):
        actions = ActionChains(self.driver)
        actions.send_keys(Keys.END).perform() 
Example #26
Source File: node.py    From capybara.py with MIT License 5 votes vote down vote up
def _action_with_modifiers(self, keys, offset):
        actions = ActionChains(self.driver.browser)
        if self._has_coords(offset):
            actions.move_to_element_with_offset(self.native, offset['x'], offset['y'])
        self._modifiers_down(actions, keys)
        yield actions
        self._modifiers_up(actions, keys)
        actions.perform() 
Example #27
Source File: node.py    From capybara.py with MIT License 5 votes vote down vote up
def hover(self):
        ActionChains(self.driver.browser).move_to_element(self.native).perform() 
Example #28
Source File: node.py    From capybara.py with MIT License 5 votes vote down vote up
def drag_to(self, element):
        ActionChains(self.driver.browser).drag_and_drop(self.native, element.native).perform() 
Example #29
Source File: test_ui.py    From todoism with MIT License 5 votes vote down vote up
def test_delete_item(self):
        self.login()
        all_item_count = self.client.find_element_by_id('all-count')
        before_count = int(all_item_count.text)

        item1 = self.client.find_element_by_xpath("//span[text()='test item 1']")
        hover_item1 = ActionChains(self.client).move_to_element(item1)
        hover_item1.perform()
        delete_button = self.client.find_element_by_class_name('delete-btn')
        delete_button.click()

        after_count = int(all_item_count.text)
        self.assertNotIn('test item 1', self.client.page_source)
        self.assertIn('test item 2', self.client.page_source)
        self.assertEqual(after_count, before_count - 1) 
Example #30
Source File: login_util.py    From bot with GNU General Public License v3.0 5 votes vote down vote up
def dismiss_this_was_me(browser):
    try:
        # click on "This was me" button if challenge page was called
        this_was_me_button = browser.find_element_by_xpath(
            read_xpath(dismiss_this_was_me.__name__, "this_was_me_button")
        )
        (ActionChains(browser).move_to_element(this_was_me_button).click().perform())
        # update server calls
        update_activity(browser, state=None)
    except NoSuchElementException:
        # no verification needed
        pass