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:
                items = obj_path.split('.')
                parent = items[:-1]
                comp = items[-1]
                obj = self.get_dataflow_figure(comp, parent)

                target = self.find_object_button(target_name)

                chain = ActionChains(self.browser)
                chain.drag_and_drop(obj.root, target)
                chain.perform()

                #obj = self.find_object_button(obj_path)
                #workflow = self.get_workflow_figure(target_name)
                #flow_fig = workflow.flow
                #chain = ActionChains(self.browser)
                #chain.move_to_element(obj)
                #chain.click_and_hold(obj)
                #chain.move_to_element(flow_fig)
                #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
    def add_object_to_workflow_figure(self, obj_path, target_name, target_page=None):
        """ Add `obj_path` object to `target_name` in workflow diagram. """

        if target_page is None:
            target_page = self

        for retry in range(3):
            try:
                items = obj_path.split('.')
                parent = items[:-1]
                comp = items[-1]
                obj = self.get_dataflow_figure(comp, parent)

                workflow = target_page.get_workflow_figure(target_name)
                flow_fig = workflow.flow

                chain = ActionChains(self.browser)
                chain.drag_and_drop(obj.root, flow_fig)
                chain.perform()
            except StaleElementReferenceException:
                if retry < 2:
                    logging.warning('add_object_to_workflow_figure:'
                                    ' StaleElementReferenceException')
                else:
                    raise
            else:
                break
Exemple #3
0
def when_i_drag_pill_from_time1_to_time2(step, pill, time1, time2):
    # get the data id for this pill
    pill = find_pill(pill)
    assert pill is not None, "No pill named %s found." % pill
    draggable = pill.find_element_by_css_selector(
        "div.pill-image span.draggable")
    assert draggable is not None, (
        "This pill is not constructed properly: %s" % pill)
    data_id = draggable.get_attribute("data-id")
    bucket = get_bucket(time1)
    assert bucket is not None, (
        "Source time slot must be specified as day or evening. "
        "No time slot called %s found" % time)
    dest = get_bucket(time2)
    assert dest is not None, (
        "Destination time slot must be specified as day or evening. "
        "No time slot called %s found" % time)

    a = bucket.find_elements_by_css_selector('span.trashable')
    assert len(a) > 0, (
        "Expected at least 1 pill in bucket %s, instead it "
        "contains %s pills" % (bucket, len(a)))
    action = False
    for dropped in a:
        if (data_id == dropped.get_attribute("data-id")):
            # found it, now, drag it to the second bucket
            action_chains = ActionChains(world.browser)
            action_chains.drag_and_drop(dropped, dest).perform()
            action = True
    assert action, (
        "No dropped pills named %s found in %s slot" % (pill, time1))
    def add_library_item_to_dataflow(self, item_name, instance_name, check=True, offset=None, prefix=None):
        """ Add component `item_name`, with name `instance_name`. """
        library_item = self.get_library_item(item_name)

        target = WebDriverWait(self.browser, TMO).until(
            lambda browser: browser.find_element_by_xpath("//*[@id='-dataflow']")
        )

        offset = offset or (90, 90)
        chain = ActionChains(self.browser)
        if False:
            chain.drag_and_drop(library_item, target)
        else:
            chain.click_and_hold(library_item)
            chain.move_to_element_with_offset(target, offset[0], offset[1])
            chain.release(None)
        chain.perform()

        page = ValuePrompt(self.browser, self.port)
        page.set_value(instance_name)
        # Check that the prompt is gone so we can distinguish a prompt problem
        # from a dataflow update problem.
        time.sleep(0.25)
        self.browser.implicitly_wait(1)  # We don't expect to find anything.
        try:
            eq(len(self.browser.find_elements(*page("prompt")._locator)), 0)
        finally:
            self.browser.implicitly_wait(TMO)

        retval = None
        if check:  # Check that it's been added.
            retval = WebDriverWait(self.browser, TMO).until(
                lambda browser: self.get_dataflow_figure(instance_name, prefix)
            )
        return retval
 def test_en_classify_products_function_drag_and_drop(self):
     driver = self.driver
     gb_login(self)
     driver.get(self.base_url + "/ev/classifyproducts")
     driver.find_element_by_xpath("//li[@id='categoryCol_category514']/div/span").click()
     # Verify process missing.
     try:
         self.assertTrue(
             self.is_element_present(
                 By.CSS_SELECTOR, "#categoryCol_subcategory515 > div.itemContent.subCategoryBg > div.handle"
             )
         )
     except AssertionError as e:
         self.verificationErrors.append(str(e))
     try:
         self.assertTrue(
             self.is_element_present(
                 By.CSS_SELECTOR, "#categoryCol_category517 > div.categoryBg.itemContent > div.blockText"
             )
         )
     except AssertionError as e:
         self.verificationErrors.append(str(e))
     element = driver.find_element_by_css_selector(
         "#categoryCol_subcategory515 > div.itemContent.subCategoryBg > div.handle"
     )
     target = driver.find_element_by_css_selector(
         "#categoryCol_category517 > div.categoryBg.itemContent > div.blockText"
     )
     action_chains = ActionChains(driver)
     action_chains.drag_and_drop(element, target)
    def test_drag(self):
        global driver
        element = driver.find_element_by_id("draggable")
        target = driver.find_element_by_id("div2")
        actions = ActionChains(driver)
        actions.drag_and_drop(element, target).perform()

        self.assertEqual("You are definitely not a bot!", driver.find_element_by_id("message").text)
    def add_library_item_to_dataflow(self, item_name, instance_name,
                                     check=True, offset=None, prefix=None,
                                     args=None):
        """ Add component `item_name`, with name `instance_name`. """
        offset = offset or (90, 90)
        xpath = "//*[@id='-dataflow']"
        library_item = self.get_library_item(item_name)
        target = WebDriverWait(self.browser, TMO).until(
                           lambda browser: browser.find_element_by_xpath(xpath))

        for retry in range(3):
            try:
                chain = ActionChains(self.browser)
                if False:
                    chain.drag_and_drop(library_item, target)
                else:
                    chain.click_and_hold(library_item)
                    chain.move_to_element_with_offset(target,
                                                      offset[0], offset[1])
                    chain.release(None)
                chain.perform()
            except StaleElementReferenceException:
                if retry < 2:
                    logging.warning('add_library_item_to_dataflow:'
                                    ' StaleElementReferenceException')
                    library_item = self.get_library_item(item_name)
                    target = WebDriverWait(self.browser, TMO).until(
                           lambda browser: browser.find_element_by_xpath(xpath))
                else:
                    raise
            else:
                break

        page = ArgsPrompt(self.browser, self.port)
        page.set_name(instance_name)
        if args is not None:
            for i, arg in enumerate(args):
                page.set_argument(i, arg)
            page.click_ok()

        # Check that the prompt is gone so we can distinguish a prompt problem
        # from a dataflow update problem.
        time.sleep(0.25)
        self.browser.implicitly_wait(1)  # We don't expect to find anything.
        try:
            eq(len(self.browser.find_elements(*page('prompt')._locator)), 0)
        finally:
            self.browser.implicitly_wait(TMO)

        retval = None
        if check:  # Check that it's been added.
            retval = WebDriverWait(self.browser, TMO).until(
                        lambda browser: self.get_dataflow_figure(instance_name,
                                                                 prefix))
        return retval
Exemple #8
0
def when_i_drop_pill_index_onto_time(step, index, time):
    idx = int(index) - 1
    a = world.firefox.find_elements_by_css_selector("div.pill")
    assert len(a) > idx, "Can't find pill %s as there are only %s pills in the list" % (index, len(a))
    pill = a[idx]
    draggable = pill.find_element_by_css_selector("div.pill-image span.draggable")
    assert draggable is not None, "This pill is not constructed properly: %s" % pill
    bucket = get_bucket(time)
    assert bucket is not None, "Time slot must be specified as day or evening. " "No time slot called %s found" % time
    action_chains = ActionChains(world.firefox)
    action_chains.drag_and_drop(draggable, bucket).perform()
 def drag_item_to_zone(self, item_value, zone_id):
     """
     Drag item to desired zone using mouse interaction.
     zone_id=None means drag item back to the item bank.
     """
     element = self._get_item_by_value(item_value)
     if zone_id is None:
         target = self._get_item_bank()
     else:
         target = self._get_zone_by_id(zone_id)
     action_chains = ActionChains(self.browser)
     action_chains.drag_and_drop(element, target).perform()
 def test_en_upload_media_function_drag_and_drop(self):
     driver = self.driver
     gb_login(self)
     driver.get(self.base_url + "/ev/uploadmedia")
     try: self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "#mediaGroup_mediaGroup604 > div.mediaGroupBg.itemContent > div.blockText"))
     except AssertionError as e: self.verificationErrors.append(str(e))
     try: self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "#media_medium187 > div.mediaBg.itemContent > div.blockText"))
     except AssertionError as e: self.verificationErrors.append(str(e))
     element = driver.find_element_by_css_selector("#media_medium187 > div.mediaBg.itemContent > div.handle")
     target = driver.find_element_by_css_selector("#mediaGroup_mediaGroup604 > div.mediaGroupBg.itemContent > div.blockText")
     action_chains = ActionChains(driver)
     action_chains.drag_and_drop(element, target);
Exemple #11
0
def when_i_drop_pill_onto_time(step, pill, time):
    pill = find_pill(pill)
    assert pill is not None, "No pill named %s found." % pill

    # get the draggable span within
    draggable = pill.find_element_by_css_selector("div.pill-image span.draggable")
    assert draggable is not None, "This pill is not constructed properly: %s" % pill

    bucket = get_bucket(time)
    assert bucket is not None, "Time slot must be specified as day or evening. " "No time slot called %s found" % time
    action_chains = ActionChains(world.firefox)
    action_chains.drag_and_drop(draggable, bucket).perform()
 def test_en_assign_accessory_function_assign(self):
     driver = self.driver
     gb_login(self)
     driver.get(self.base_url + "/ev/assignaccessories")
     driver.find_element_by_xpath("//li[@id='categories_category517']/div/span").click()
     driver.find_element_by_xpath("//li[@id='accessories_category514']/div/span").click()
     try: self.assertTrue(self.is_element_present(By.XPATH, "//li[@id='accessories_accessory636']/div/div"))
     except AssertionError as e: self.verificationErrors.append(str(e))
     try: self.assertTrue(self.is_element_present(By.XPATH, "//li[@id='products_product637']/div/div"))
     except AssertionError as e: self.verificationErrors.append(str(e))
     element = driver.find_element_by_xpath("//li[@id='accessories_accessory636']/div/div")
     target = driver.find_element_by_xpath("//li[@id='products_product637']/div/div")
     action_chains = ActionChains(driver)
     action_chains.drag_and_drop(element, target);
 def test_en_setup_users_or_groups_function_assign_uassign_user_group(self):
     driver = self.driver
     gb_login(self)
     driver.get(self.base_url + "/ev/setupusersorgroups")
     try: self.assertTrue(self.is_element_present(By.XPATH, "//li[@id='userGroup_userGroup"+testUserGroupIdValue+"']/div/div"))
     except AssertionError as e: self.verificationErrors.append(str(e))
     #driver.find_element_by_xpath("//li[@id='hierarchy_storeGroup202']/div/span").click()
     #try: self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "#hierarchy_store203 > div.itemContent.storeBg > div.blockText"))
     #except AssertionError as e: self.verificationErrors.append(str(e))
     try: self.assertTrue(self.is_element_present(By.CSS_SELECTOR, "#hierarchy_store"+assignStoreIdValue+" > div.itemContent.storeBg > div.blockText"))
     except AssertionError as e: self.verificationErrors.append(str(e))
     element = driver.find_element_by_xpath("//li[@id='userGroup_userGroup"+testUserGroupIdValue+"']/div/div")
     target = driver.find_element_by_css_selector("#hierarchy_store"+assignStoreIdValue+" > div.itemContent.storeBg > div.blockText")
     action_chains = ActionChains(driver)
     action_chains.drag_and_drop(element, target);
    def test_edit_site(self):
        print "Create site test is commencing."
        wait = WebDriverWait(self.driver, self.waitTime)
        self.driver.get(self.url)

        print "Starting logging in."
        wait.until(EC.element_to_be_clickable((By.ID, "login-button"))).click()
        wait.until(EC.element_to_be_clickable((By.ID, "weebly-username"))).click()
        wait.until(EC.element_to_be_clickable((By.ID, "weebly-password"))).click()
        Username = self.driver.find_element_by_id("weebly-username")
        Username.send_keys(self.email)
        Password = self.driver.find_element_by_id("weebly-password")
        Password.send_keys(self.password)
        wait.until(EC.element_to_be_clickable((By.XPATH, "//form[@id='weebly-login']/p[4]/input"))).click()

        print "Selecting Site to edit."
        wait.until(EC.presence_of_element_located((By.LINK_TEXT, "Jon's Site")))
        self.driver.find_element_by_link_text("Jon's Site").click()

        print "Finding another text  object from toolbar and starting drag and drop."
        wait.until(EC.presence_of_element_located((By.ID, "secondlist")))
        self.driver.find_element_by_xpath("//li[2]/div[2]").click()
        text = self.driver.find_element_by_xpath("//li[2]/div[2]")
        text_target = self.driver.find_element_by_id("secondlistParent")
        drag_text = ActionChains(self.driver)
        drag_text.drag_and_drop(text, text_target).perform()
        time.sleep(2)
        self.driver.find_element_by_xpath("//li[3]/div[2]/div/div").click()
        time.sleep(2)
        self.driver.find_element_by_xpath("//li[3]/div[2]/div/div").clear()
        time.sleep(2)
        self.driver.find_element_by_xpath("//li[3]/div[2]/div/div").send_keys(
            "Drag and drop text area testing text input for third item."
        )
        time.sleep(2)
        self.driver.find_element_by_id("secondlist").click()
        time.sleep(5)
        print "Drag and drop should now be complete."

        print "Exit the editor."
        wait.until(EC.element_to_be_clickable((By.XPATH, "//li[@id='more-drop-button']/a/span"))).click()
        wait.until(EC.element_to_be_clickable((By.LINK_TEXT, "Exit Editor"))).click()
        print "Exited the editor"

        print "Log out"
        wait.until(EC.element_to_be_clickable((By.LINK_TEXT, "Logout"))).click()
        print "Logged out!"
    def test_reorder_components(self):
        self.add_component('hypothesis', 'first')
        self.add_component('hypothesis', 'second')

        self.driver.get(self.project_url)

        # Second method: by element
        ac = ActionChains(self.driver)
        a = self.driver.find_element_by_css_selector('#Nodes li:first-child')
        b = self.driver.find_element_by_css_selector('#Nodes li:last-child')
        ac.drag_and_drop(a, b).perform()

        self.driver.get(self.project_url)
        self.assertEqual(
            self.get_element('#Nodes li:first-child').text,
            'second',
        )
    def perform_drag_drop(self, from_group_id, to_group_id):
        from_group_element = self.driver.find_element(
            By.CLASS_NAME, "group-{0}".format(from_group_id))
        item = self.find_element_in(
            from_group_element, By.CSS_SELECTOR, ".items .item-info", wait=0)
        move_handle = self.find_element_in(item, By.CLASS_NAME, "move-handle", wait=0)
        target = self.find_element(
            By.CLASS_NAME, "group-{0}".format(to_group_id), wait=0)
        item_title = self.find_element_in(item, By.CLASS_NAME, "item-link", wait=0).text

        from selenium.webdriver import ActionChains
        action_chains = ActionChains(self.driver)
        action_chains.move_to_element(item)
        action_chains.drag_and_drop(move_handle, target)
        action_chains.perform()

        return item_title
    def test_CBT(self):
        # We wrap this all in a try/except so we can set pass/fail at the end
        try:
            # load the page url
            print('Loading Url')
            self.driver.get('http://crossbrowsertesting.github.io/drag-and-drop.html')

            # maximize the window - DESKTOPS ONLY
            # print('Maximizing window')
            # self.driver.maximize_window()

            # grab the first element
            print('Grabbing draggable element')
            draggable = self.driver.find_element_by_id("draggable")
            
            # then the second element
            print('Grabbing the droppable element')
            droppable = self.driver.find_element_by_id("droppable")
            
            # we use ActionChains to move the element
            print('Dragging the element')
            actionChains = ActionChains(self.driver)
            actionChains.drag_and_drop(draggable, droppable).perform()

            # let's assert that the droppable element is in the state we want it to be
            droppableText = self.driver.find_element_by_xpath('//*[@id="droppable"]/p').text
            self.assertEqual('Dropped!', droppableText)

            print("Taking snapshot")
            snapshot_hash = self.api_session.post('https://crossbrowsertesting.com/api/v3/selenium/' + self.driver.session_id + '/snapshots').json()['hash']

            # if we are still in the try block after all of our assertions that
            # means our test has had no failures, so we set the status to "pass"
            self.test_result = 'pass'

        except AssertionError as e:
            # log the error message, and set the score to "during tearDown()".
            self.api_session.put('https://crossbrowsertesting.com/api/v3/selenium/' + self.driver.session_id + '/snapshots/' + snapshot_hash,
                data={'description':"AssertionError: " + str(e)})
            self.test_result = 'fail'
            raise
from selenium import webdriver
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
import re

from selenium.webdriver import  ActionChains


driver = webdriver.Chrome(executable_path="/Users/LAL/PycharmProjects/Python/WebScrapingWithPython/Chapter10_Scraping JavaScript/Selenium Tutorial/chromedriver")

driver.get("http://www.w3schools.com/html/html5_draganddrop.asp")

source = driver.find_element_by_id('div1')
target = driver.find_element_by_id('div2')
action_chains = ActionChains(driver)
action_chains.drag_and_drop(source,target).perform()




Exemple #19
0
 def move_src_dest(self,src_loc_type,src_loc_val,dest_loc_type,dest_loc_val):
     a = ActionChains(self.driver)
     src_element = self.locator(src_loc_type,src_loc_val)
     des_element=self.locator(dest_loc_type,dest_loc_val)
     a.drag_and_drop(src_element, des_element).perform()
drops = driver.find_elements_by_css_selector(".ui-droppable")

blue_drop = drops[0]
red_drop = drops[1]
orange_drop = drops[2]


blue_chain = ActionChains(driver)
red_chain = ActionChains(driver)
orange_chain = ActionChains(driver)


driver.save_screenshot("1.png")


blue_chain.drag_and_drop(blue,blue_drop).perform()
driver.save_screenshot("2.png")

red_chain.drag_and_drop(red,red_drop).perform()
driver.save_screenshot("3.png")

orange_chain.drag_and_drop(orange,orange_drop).perform()
driver.save_screenshot("4.png")


check_button = driver.find_element_by_class_name("h5p-question-check-answer")

check_button.click()

driver.save_screenshot("5.png")
    def test_create_site(self):
        print "Create site test is commencing."
        wait = WebDriverWait(self.driver, self.waitTime)
        self.driver.get(self.url)
        print "Starting logging in."
        wait.until(EC.element_to_be_clickable((By.ID, 'login-button'))).click()
        wait.until(
            EC.element_to_be_clickable((By.ID, 'weebly-username'))).click()
        wait.until(
            EC.element_to_be_clickable((By.ID, 'weebly-password'))).click()
        Username = self.driver.find_element_by_id('weebly-username')
        Username.send_keys(self.email)
        Password = self.driver.find_element_by_id('weebly-password')
        Password.send_keys(self.password)
        print "Login successful."
        try:
            wait.until(EC.element_to_be_clickable(
                (By.XPATH, "//form[@id='weebly-login']/p[4]/input"))).click()
        except:
            print "The elements do not exist"

        print "Clicking create site button."
        wait.until(EC.element_to_be_clickable((By.ID, 'create-site-button'))).click()
        wait.until(EC.element_to_be_clickable((By.ID, 'create-site-button'))).click()
        print "Clicked create site button."
        time.sleep(2)

        print "A/B Testing site type if it appears."
        try:
            self.driver.find_element_by_xpath("//div[2]/div/div/div").click()
        except:
            print "No A/B test appeared."
        time.sleep(2)

        print "Selecting site theme of: First Theme"
        wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "img[alt=\"Lucent\"]")))
        wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "button.btn.btn-primary")))
        hover_element = self.driver.find_element_by_css_selector("img[alt=\"Lucent\"]")
        action_chains = ActionChains(self.driver)
        action_chains.move_to_element(hover_element).perform()
        theme = self.driver.find_element_by_xpath(
            "//ul[@id='w-theme-list']/li[2]/div/img")
        wait.until(EC.element_to_be_clickable(
            (By.XPATH, "//ul[@id='w-theme-list']/li[2]/div/div/div/button"))).click()
        print "Theme Selected"

        print "Selecting Domain"
        wait.until(EC.element_to_be_clickable(
            (By.XPATH, "//div[@id='chooseDomainDiv']/div[2]/a/span")
        ))
        self.driver.find_element_by_xpath(
            "//div[@id='domainSubdomain']/div/input").click()
        DomainName = self.driver.find_element_by_id('weeblyDomain')
        DomainName.send_keys(self.domain)
        self.driver.find_element_by_xpath(
            "//div[@id='chooseDomainDiv']/div[2]/a/span").click()

        print "Editing the existing title."
        self.driver.find_element_by_id("wsite-title").click()
        time.sleep(1)
        self.driver.find_element_by_id("wsite-title").clear()
        time.sleep(1)
        self.driver.find_element_by_id("wsite-title").send_keys("Jon's Site")
        time.sleep(1)

        print "Finding title from toolbar starting drag and drop"
        self.driver.find_element_by_css_selector("div.title-box").click()
        title = self.driver.find_element_by_css_selector("div.title-box")
        title_target = self.driver.find_element_by_id("empty-message-inner")
        drag_title = ActionChains(self.driver)
        drag_title.drag_and_drop(title, title_target).perform()
        time.sleep(3)
        self.driver.find_element_by_xpath("//div[2]/div/h2").click()
        time.sleep(1)
        self.driver.find_element_by_xpath("//div[2]/div/h2").clear()
        time.sleep(1)
        self.driver.find_element_by_xpath("//div[2]/div/h2").send_keys("Drag and drop title text change.")
        time.sleep(1)
        self.driver.find_element_by_xpath("//li[2]/div[2]").click()
        time.sleep(1)
        print "Drag and drop title sould now be complete."

        time.sleep(2)

        print "Finding text from toolbar and starting drag and drop."
        try:
            self.assertTrue(self.is_element_present(By.ID, "secondlist"))
        except AssertionError as e:
            self.verificationErrors.append(str(e))
        wait.until(EC.presence_of_element_located((By.ID, "secondlist")))
        self.driver.find_element_by_xpath("//li[2]/div[2]").click()
        text = self.driver.find_element_by_xpath("//li[2]/div[2]")
        text_target = self.driver.find_element_by_id("secondlistParent")
        drag_text = ActionChains(self.driver)
        drag_text.drag_and_drop(text, text_target).perform()
        time.sleep(2)
        self.driver.find_element_by_xpath("//li[2]/div[2]/div/div").click()
        time.sleep(2)
        self.driver.find_element_by_xpath("//li[2]/div[2]/div/div").clear()
        time.sleep(2)
        self.driver.find_element_by_xpath("//li[2]/div[2]/div/div").send_keys("Drag and drop text area testing text input.")
        time.sleep(2)
        self.driver.find_element_by_id("secondlist").click()
        time.sleep(5)
        print "Drag and drop should now be complete."

        print "Exit the editor."
        wait.until(EC.element_to_be_clickable(
            (By.XPATH, "//li[@id='more-drop-button']/a/span"))).click()
        wait.until(EC.element_to_be_clickable(
            (By.LINK_TEXT, "Exit Editor"))).click()
        print "Exited the editor"

        print "Log out"
        wait.until(EC.element_to_be_clickable((By.LINK_TEXT, "Logout"))
                   ).click()
        print "Logged out!"
    def test_storymap(self):
        factories.UserFactory.create(
            email="*****@*****.**",
            password="******",
            is_staff=True,
        )
        self._login("*****@*****.**", "123")
        time.sleep(0.2)
        storymap = factories.StoryMapFactory.create()
        self.browser.get(self.live_reverse("storymap_detail",
                                           args=(storymap.pk,)))
        time.sleep(0.2)
        # Create 2 themes
        for seq in range(2):
            self.sel_query("a.create_theme").click()
            time.sleep(0.2)
            theme_input = self.sel_query("#theme-create-panel textarea")
            theme_input.send_keys("Theme {0}".format(seq))
            self.sel_query("#create-theme-btn").click()
            time.sleep(0.5)
        # Create 2 phase
        for seq in range(2):
            self.sel_query("a.create_phase").click()
            time.sleep(0.2)
            theme_input = self.sel_query("#phase-create-panel textarea")
            theme_input.send_keys("Phase {0}".format(seq))
            self.sel_query("#create-phase-btn").click()
            time.sleep(0.5)
        # let's move to the theme and phase to display the "new story" button
        actionChains = ActionChains(self.browser)
        actionChains.move_to_element(self.sel_query(".stories-zone"))
        actionChains.perform()
        time.sleep(0.2)
        self.sel_query(".create_story").click()
        time.sleep(0.2)
        actionChains = ActionChains(self.browser)
        actionChains.send_keys("My first story\n")
        actionChains.perform()
        time.sleep(0.2)

        actionChains = ActionChains(self.browser)
        actionChains.move_to_element(self.sel_query(".stories-zone"))
        actionChains.perform()
        time.sleep(0.2)
        self.sel_query(".create_story").click()
        actionChains = ActionChains(self.browser)
        actionChains.send_keys("My second story\n")
        actionChains.perform()
        time.sleep(0.2)

        story = Story.objects.get(title="My first story")
        phase_1 = Phase.objects.get(name="Phase 1")
        theme_0 = Theme.objects.get(name="Theme 0")

        # move story to another phase
        actionChains = ActionChains(self.browser)
        actionChains.drag_and_drop(
            self.sel_query('.story-cell[story-id="{0}"]'.format(story.pk)),
            self.sel_query('.stories-zone[phase-id="{0}"]'.format(phase_1.pk)),
        )
        actionChains.perform()
        time.sleep(0.2)

        storymap = StoryMap.objects.get(pk=storymap.pk)
        self.assertEqual(storymap.themes.all()[0].name, "Theme 0")
        self.assertEqual(storymap.themes.all()[1].name, "Theme 1")
        self.assertEqual(storymap.phases.all()[0].name, "Phase 0")
        self.assertEqual(storymap.phases.all()[1].name, "Phase 1")
        story = Story.objects.get(title="My first story")
        self.assertEqual(story.phase_id, phase_1.pk)
        self.assertEqual(story.theme_id, theme_0.pk)

        # Edit story
        actionChains = ActionChains(self.browser)
        actionChains.click(self.sel_query(
            '.story-cell[story-id="{0}"] .story'.format(
                story.pk
            )
        ))
        actionChains.perform()
        actionChains = ActionChains(self.browser)
        actionChains.send_keys(" Edited\n")
        actionChains.perform()
        time.sleep(1)

        self.assertTrue(Story.objects.get(title="My first story Edited"))

        # delete theme 1
        theme = Theme.objects.get(name="Theme 1")
        actionChains = ActionChains(self.browser)
        actionChains.move_to_element(self.sel_query(
            '.theme-cell[theme-id="{0}"]'.format(theme.pk)))
        actionChains.click(self.sel_query(
            '.theme-cell[theme-id="{0}"] .delete_theme'.format(theme.pk)))
        actionChains.perform()
        time.sleep(0.2)
        self.sel_query("#confirm-delete-btn").click()
        time.sleep(0.5)

        # delete phase 0
        phase = Phase.objects.get(name="Phase 0")
        actionChains = ActionChains(self.browser)
        actionChains.move_to_element(self.sel_query(
            '.phase-cell[phase-id="{0}"]'.format(phase.pk)))
        actionChains.click(self.sel_query(
            '.phase-cell[phase-id="{0}"] .delete_phase'.format(phase.pk)))
        actionChains.perform()
        time.sleep(0.2)
        self.sel_query("#confirm-delete-btn").click()
        time.sleep(0.5)

        # delete last story
        actionChains = ActionChains(self.browser)
        actionChains.move_to_element(self.sel_query(
            '.story-cell[story-id="{0}"]'.format(story.pk)))
        actionChains.click(self.sel_query(
            '.story-cell[story-id="{0}"] .delete_story'.format(story.pk)))
        actionChains.perform()
        time.sleep(0.2)
        self.sel_query("#confirm-delete-btn").click()
        time.sleep(0.5)

        # Only one story theme and phase should exists
        self.assertFalse(Story.objects.exists())
        self.assertTrue(Theme.objects.get())
        self.assertTrue(Theme.objects.get())
Exemple #23
0
 def draganddrop(self, source, destination):
     acc = ActionChains(self.driver)
     acc.drag_and_drop(source, destination).perform()
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
import unittest, time, re

driver = webdriver.Firefox()
driver.get("https://www.google.ch/maps/place/View+Rd,+London+N6+4DJ,+Vereinigtes+K%C3%B6nigreich/@51.5779648,-0.1529593,3a,75y,306.58h,90t/data=!3m7!1e1!3m5!1s7zSuwLCG_H9VDTHefa8cBg!2e0!6s%2F%2Fgeo3.ggpht.com%2Fcbk%3Fpanoid%3D7zSuwLCG_H9VDTHefa8cBg%26output%3Dthumbnail%26cb_client%3Dmaps_sv.tactile.gps%26thumb%3D2%26w%3D203%26h%3D100%26yaw%3D320.06158%26pitch%3D0!7i13312!8i6656!4m2!3m1!1s0x48761a4799e86c71:0x54305e42988401c2")
time.sleep(1)
actions = ActionChains(driver)
source = driver.find_element_by_css_selector("canvas.widget-scene-canvas")
for i in range(10):
	actions.drag_and_drop(source,source).perform()

driver.save_screenshot('screenie.png')
print "waiting ..."
time.sleep(2)
print "closing"
driver.close()
from selenium import webdriver
from selenium.webdriver import ActionChains

browser = webdriver.Chrome()
browser.get(
    'http://www.runoob.com/try/try.php?filename=jqueryui-api-droppable')
browser.switch_to.frame('iframResult')
source = browser.find_element_by_css_selector('#draggable')
target = browser.find_element_by_css_selector('#droppable')

action = ActionChains(browser)
action.drag_and_drop(source, target)
action.perform()
Exemple #26
0
from selenium import webdriver
from selenium.webdriver import ActionChains

driver = webdriver.Chrome()
driver.get("https://jqueryui.com/droppable/")

print("URL provided")

driver.implicitly_wait(30)

frame = driver.find_element_by_xpath("//*[@class='demo-frame']")
# frame=driver.find_element_by_class_name("demo-frame")
driver.switch_to.frame(frame)

print("Switch to iframe")

drag = driver.find_element_by_id("draggable")
print("Captured drag element")

drop = driver.find_element_by_id("droppable")
print("Captured drop element")

a = ActionChains(driver)
a.drag_and_drop(drag, drop).perform()
print("drag and drop completed")

# frame,drag,drop are variables
 def dragAndDrop(self, source, target, descriptionSource, descriptionTarget):
     self.action("drag " + descriptionSource + " to " + descriptionTarget)
     actionChains = ActionChains(self.DRIVER)
     actionChains.drag_and_drop(source, target).perform()
Exemple #28
0
 def drag_and_drop(self, source_element, target_element):
     action_chains = ActionChains(self.browser)
     action_chains.drag_and_drop(source_element, target_element)
     action_chains.perform()
     self.sleep(1)
Exemple #29
0
from selenium import webdriver
from selenium.webdriver import ActionChains


driver=webdriver.Chrome(executable_path="C:/Users/Admin/Downloads/chromedriver.exe")
driver.get("https://jqueryui.com/droppable/")
framewar=driver.find_element_by_xpath("//iframe[@class='demo-frame']")
driver.switch_to_frame(framewar)
print("Switch to frame")

src_drag=driver.find_element_by_id("draggable")
print("Capturing the source value")

dest_drag=driver.find_element_by_id("droppable")
print("Capture the destination value")

a=ActionChains(driver)
a.drag_and_drop(src_drag,dest_drag).perform()
print("dragged and dropped to the required source")






#!/usr/bin/env python
# coding=utf-8

from selenium import webdriver
from selenium.webdriver import ActionChains


brower = webdriver.Firefox()    # 模拟火狐浏览器
url = 'http://www.runoob.com/try/try.php?filename=jqueryui-api-droppable'
brower.get(url)
brower.switch_to.frame("iframeResult")
source = brower.find_element_by_css_selector('#draggable')
target = brower.find_element_by_css_selector("#droppable")
action = ActionChains(brower)
action.drag_and_drop(source, target)
action.perform()

Exemple #31
0
    def test_create_site(self):
        print "Create site test is commencing."
        wait = WebDriverWait(self.driver, self.waitTime)
        self.driver.get(self.url)
        print "Starting logging in."
        wait.until(EC.element_to_be_clickable((By.ID, 'login-button'))).click()
        wait.until(EC.element_to_be_clickable(
            (By.ID, 'weebly-username'))).click()
        wait.until(EC.element_to_be_clickable(
            (By.ID, 'weebly-password'))).click()
        Username = self.driver.find_element_by_id('weebly-username')
        Username.send_keys(self.email)
        Password = self.driver.find_element_by_id('weebly-password')
        Password.send_keys(self.password)
        print "Login successful."
        try:
            wait.until(
                EC.element_to_be_clickable(
                    (By.XPATH,
                     "//form[@id='weebly-login']/p[4]/input"))).click()
        except:
            print "The elements do not exist"

        print "Clicking create site button."
        wait.until(EC.element_to_be_clickable(
            (By.ID, 'create-site-button'))).click()
        wait.until(EC.element_to_be_clickable(
            (By.ID, 'create-site-button'))).click()
        print "Clicked create site button."
        time.sleep(2)

        print "A/B Testing site type if it appears."
        try:
            self.driver.find_element_by_xpath("//div[2]/div/div/div").click()
        except:
            print "No A/B test appeared."
        time.sleep(2)

        print "Selecting site theme of: First Theme"
        wait.until(
            EC.presence_of_element_located(
                (By.CSS_SELECTOR, "img[alt=\"Lucent\"]")))
        wait.until(
            EC.presence_of_element_located(
                (By.CSS_SELECTOR, "button.btn.btn-primary")))
        hover_element = self.driver.find_element_by_css_selector(
            "img[alt=\"Lucent\"]")
        action_chains = ActionChains(self.driver)
        action_chains.move_to_element(hover_element).perform()
        theme = self.driver.find_element_by_xpath(
            "//ul[@id='w-theme-list']/li[2]/div/img")
        wait.until(
            EC.element_to_be_clickable((
                By.XPATH,
                "//ul[@id='w-theme-list']/li[2]/div/div/div/button"))).click()
        print "Theme Selected"

        print "Selecting Domain"
        wait.until(
            EC.element_to_be_clickable(
                (By.XPATH, "//div[@id='chooseDomainDiv']/div[2]/a/span")))
        self.driver.find_element_by_xpath(
            "//div[@id='domainSubdomain']/div/input").click()
        DomainName = self.driver.find_element_by_id('weeblyDomain')
        DomainName.send_keys(self.domain)
        self.driver.find_element_by_xpath(
            "//div[@id='chooseDomainDiv']/div[2]/a/span").click()

        print "Editing the existing title."
        self.driver.find_element_by_id("wsite-title").click()
        time.sleep(1)
        self.driver.find_element_by_id("wsite-title").clear()
        time.sleep(1)
        self.driver.find_element_by_id("wsite-title").send_keys("Jon's Site")
        time.sleep(1)

        print "Finding title from toolbar starting drag and drop"
        self.driver.find_element_by_css_selector("div.title-box").click()
        title = self.driver.find_element_by_css_selector("div.title-box")
        title_target = self.driver.find_element_by_id("empty-message-inner")
        drag_title = ActionChains(self.driver)
        drag_title.drag_and_drop(title, title_target).perform()
        time.sleep(3)
        self.driver.find_element_by_xpath("//div[2]/div/h2").click()
        time.sleep(1)
        self.driver.find_element_by_xpath("//div[2]/div/h2").clear()
        time.sleep(1)
        self.driver.find_element_by_xpath("//div[2]/div/h2").send_keys(
            "Drag and drop title text change.")
        time.sleep(1)
        self.driver.find_element_by_xpath("//li[2]/div[2]").click()
        time.sleep(1)
        print "Drag and drop title sould now be complete."

        time.sleep(2)

        print "Finding text from toolbar and starting drag and drop."
        try:
            self.assertTrue(self.is_element_present(By.ID, "secondlist"))
        except AssertionError as e:
            self.verificationErrors.append(str(e))
        wait.until(EC.presence_of_element_located((By.ID, "secondlist")))
        self.driver.find_element_by_xpath("//li[2]/div[2]").click()
        text = self.driver.find_element_by_xpath("//li[2]/div[2]")
        text_target = self.driver.find_element_by_id("secondlistParent")
        drag_text = ActionChains(self.driver)
        drag_text.drag_and_drop(text, text_target).perform()
        time.sleep(2)
        self.driver.find_element_by_xpath("//li[2]/div[2]/div/div").click()
        time.sleep(2)
        self.driver.find_element_by_xpath("//li[2]/div[2]/div/div").clear()
        time.sleep(2)
        self.driver.find_element_by_xpath("//li[2]/div[2]/div/div").send_keys(
            "Drag and drop text area testing text input.")
        time.sleep(2)
        self.driver.find_element_by_id("secondlist").click()
        time.sleep(5)
        print "Drag and drop should now be complete."

        print "Exit the editor."
        wait.until(
            EC.element_to_be_clickable(
                (By.XPATH, "//li[@id='more-drop-button']/a/span"))).click()
        wait.until(EC.element_to_be_clickable(
            (By.LINK_TEXT, "Exit Editor"))).click()
        print "Exited the editor"

        print "Log out"
        wait.until(EC.element_to_be_clickable(
            (By.LINK_TEXT, "Logout"))).click()
        print "Logged out!"
Exemple #32
0
def dragAndDrop(driver, src, tgt):
    act = ActionChains(driver)
    act.drag_and_drop(src, tgt).perform()
print "Desired Capabilities returned by server:\n"
print Sikuli_driver.desired_capabilities
print ""

# launch browser to Drag & drop page for demo test
browser.get("http://html5demos.com/drag")

if len(browser.find_elements_by_tag_name("li")) != 5:
	print "Drag & drop test page not in correct state for demo test"

time.sleep(5)

src = Sikuli_driver.find_element_by_name('drag_src_html5.png')
target = Sikuli_driver.find_element_by_name('drop_target_html5.png')
actions = ActionChains(Sikuli_driver)
actions.drag_and_drop(src,target).perform()

# check results, drag & drop reduced items by 1 from 5 to 4
result = len(browser.find_elements_by_tag_name('li'))
if result != 4:
    print 'Drag & drop failed. There are %d items when there should be 4.\n' % result
else:
    print 'Drag & drop success.\n'

browser.quit()
Sikuli_driver.quit()

# Now imagine from this integration demo, you could use Sikuli with browser via
# WebDriver to do stuff like file download, HTTP authentication and other stuff
# like drag item from desktop into browser, that you could not do w/ WebDriver
# alone, or w/ executing shell commands and other external stuff. Now can do all
Exemple #34
0
from selenium import webdriver
from selenium.webdriver import ActionChains

#模拟拖拽
browser = webdriver.Chrome()
url = 'http://www.runoob.com/try/try.php?filename=jqueryui-api-droppable'
browser.get(url)
browser.switch_to.frame('iframeResult')  #切换到内部的iframe框架
source = browser.find_element_by_css_selector('#draggable')  #选择源
target = browser.find_element_by_css_selector('#droppable')  #选择目标
print(source, target)
actions = ActionChains(browser)  #创建动作链对象
actions.drag_and_drop(source, target)  #设计动作
###重点
actions.perform()  #开始你的表演
from selenium import webdriver
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver import ActionChains

driver = webdriver.PhantomJS(executable_path='../../phantomjs/bin/phantomjs')
driver.get('http://pythonscraping.com/pages/javascript/draggableDemo.html')

print (driver.find_element_by_id('message').text)

element = driver.find_element_by_id('draggable')
target = driver.find_element_by_id('div2')
actions = ActionChains(driver)
actions.drag_and_drop(element, target).perform()

print (driver.find_element_by_id('message').text)
Exemple #36
0
driver.maximize_window()

elem_rome = driver.find_element(By.ID, "box6")
elem_madrid = driver.find_element(By.ID, "box7")
elem_oslo = driver.find_element(By.ID, "box1")
elem_copenhagen = driver.find_element(By.ID, "box4")
elem_seoul = driver.find_element(By.ID, "box5")
elem_stockholm = driver.find_element(By.ID, "box2")
elem_washington = driver.find_element(By.ID, "box3")

elem_italy = driver.find_element(By.ID, "box106")
elem_spain = driver.find_element(By.ID, "box107")
elem_norway = driver.find_element(By.ID, "box101")
elem_denmark = driver.find_element(By.ID, "box104")
elem_south_korea = driver.find_element(By.ID, "box105")
elem_sweden = driver.find_element(By.ID, "box102")
elem_united_states = driver.find_element(By.ID, "box103")

action = ActionChains(driver)

action.drag_and_drop(elem_rome, elem_italy)
action.drag_and_drop(elem_madrid, elem_spain)
action.drag_and_drop(elem_oslo, elem_norway)
action.drag_and_drop(elem_copenhagen, elem_denmark)
action.drag_and_drop(elem_seoul, elem_south_korea)
action.drag_and_drop(elem_stockholm, elem_sweden)
action.drag_and_drop(elem_washington, elem_united_states).perform()

time.sleep(3)
driver.close()
Exemple #37
0
	action.move_to_element(photo).perform()

	# 单击指定节点
	action.move_to_element(photo).click(photo).perform()

	# 双击指定节点
	action.move_to_element(photo).double_click(photo).perform()

	# 右击指定节点
	action.move_to_element(photo).context_click(photo).perform()

	# 左键hold住指定节点
	action.move_to_element(photo).click_and_hold(photo).perform()

	# 把photo节点拖拽到next节点
	action.drag_and_drop(photo, driver.find_element_by_id('next')).perform()

----------------------------
表单填充					|
----------------------------
	* 已经知道了怎样向文本框中输入文字
	* 但是有时候我们会碰到<select> </select>标签的下拉框,直接点击下拉框中的选项不一定可行
	* Selenium专门提供了Select类来处理下拉框
		# 导入 Select 类
		from selenium.webdriver.support.ui import Select

		# 找到 name 的选项卡
		select = Select(driver.find_element_by_name('status'))

		# 根据下拉项的位置选择
		select.select_by_index(1)
Exemple #38
0
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver import ActionChains

driver = webdriver.Chrome(
    "C:/Users/anaso/PycharmProjects/Selenium/Selenium Scripts/Drivers/chromedriver.exe"
)
driver.maximize_window()

driver.get(
    "http://www.dhtmlgoodies.com/scripts/drag-drop-custom/demo-drag-drop-3.html"
)
driver.set_page_load_timeout(4)
n = len(driver.find_elements(By.CLASS_NAME, "dragableBox")) // 2
print(n)
time.sleep(2)
#driver.find_element_by_id("box1").click()
for i in range(1, n + 1):
    box = driver.find_element(By.ID, "box" + str(i) + "")
    target = driver.find_element(By.ID, "box10" + str(i) + "")
    action = ActionChains(driver)
    action.drag_and_drop(box, target).perform()
    time.sleep(1)
from selenium import webdriver
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver import ActionChains

driver = webdriver.PhantomJS(executable_path='phantomjs/bin/phantomjs')
driver.get('http://pythonscraping.com/pages/javascript/draggableDemo.html')

print(driver.find_element_by_id("message").text)

element = driver.find_element_by_id("draggable")
target = driver.find_element_by_id("div2")
actions = ActionChains(driver)
actions.drag_and_drop(element, target).perform()

print(driver.find_element_by_id("message").text)
Exemple #40
0
 def drag_and_drop(self, target: Element):
     with allure.step(f"拖拽 {self.describe} 至 {target.describe}"):
         action = ActionChains(self.driver)
         action.drag_and_drop(self.present, target).perform()
     return target
Exemple #41
0
# 1.导包
import time
from selenium import webdriver
from selenium.webdriver import ActionChains

# 2.创建浏览器驱动对象
driver = webdriver.Chrome()
driver.maximize_window()
# 3.打开测试网址打开注册A.html页面,完成以下操作
driver.get("file:///C:/Users/sandysong/Desktop/pagetest/drag.html")
# 4.业务操作
# 创建鼠标对象
# 拖拽某个元素到指定位置
mouse = ActionChains(driver)
mouse.drag_and_drop(driver.find_element_by_id("div1"),
                    driver.find_element_by_id("div2"))
mouse.perform()
# 5.3秒后关闭浏览器窗口
time.sleep(3)
driver.quit()
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import ActionChains
import time

driver = webdriver.Firefox()
driver.get("http://engineering.aweber.com/getting-started-with-ui-automated-tests-using-selenium-python/")
search = driver.find_element_by_id("search")
element = driver.find_element_by_xpath("//a[@href='http://engineering.aweber.com/category/apis/']")
element.click()
action_chains = ActionChains(driver)
action_chains.drag_and_drop(element, search).perform()
time.sleep(3)
driver.close()
Exemple #43
0
# -*- coding: utf-8 -*-

__author__ = "苦叶子"

from selenium import webdriver
from selenium.webdriver import ActionChains

if __name__ == "__main__":
    driver = webdriver.Chrome()
    action_chains = ActionChains(driver)
    driver.get("http://www.python.org")

    # 获取About链接元素,并加入动作链
    About = driver.find_element_by_link_text("About")

    Events = driver.find_element_by_link_text("Events")
    action_chains.drag_and_drop(About, Events)
    action_chains.pause(2)

    # 执行动作链
    action_chains.perform()

    driver.quit()
Exemple #44
0
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select

import unittest
from selenium.webdriver import ActionChains

driver = webdriver.Chrome()
driver.maximize_window()
driver.get(
    "http://www.dhtmlgoodies.com/scripts/drag-drop-custom/demo-drag-drop-3.html"
)
time.sleep(2)
source = driver.find_element_by_xpath("//*[@id='box2']")
target = driver.find_element_by_xpath("//*[@id='box105']")

actions = ActionChains(driver)

actions.drag_and_drop(source, target).perform()
Exemple #45
0
 def drag_and_drop(self, source, target):
     from selenium.webdriver import ActionChains
     action = ActionChains(self.driver)
     action.drag_and_drop(source, target)
 def ClickSelectYear(self):
     drag = self.browser.find_element(*self.slider_left_button)
     drop = self.browser.find_element(*self.slider_right_button)
     actionchains = ActionChains(self.browser)
     actionchains.drag_and_drop(drag, drop).perform()
class TestActionChains():
    def setup(self):
        self.driver = webdriver.Chrome()
        self.action = ActionChains(self.driver)
        self.driver.maximize_window()
        self.driver.implicitly_wait(5)

    def teardown(self):
        self.driver.quit()

    @pytest.mark.skip  # 忽略这个用例
    def test_case_click(self):
        self.driver.get('http://sahitest.com/demo/clicks.htm')
        ele_click = self.driver.find_element_by_xpath(
            '//input[@value="click me"]')
        ele_double = self.driver.find_element_by_xpath(
            '//input[@value="dbl click me"]')
        ele_right = self.driver.find_element_by_xpath(
            '//input[@value="right click me"]')
        self.action.click(ele_click)
        self.action.context_click(ele_right)  # 右键点击
        self.action.double_click(ele_double)
        sleep(3)
        self.action.perform()  # 执行以上动作
        sleep(3)

    @pytest.mark.skip
    def test_move_to(self):
        self.driver.get('http://www.baidu.com')
        ele = self.driver.find_element_by_id('s-usersetting-top')  # 百度首页的设置
        self.action.move_to_element(ele)
        self.action.perform()

    @pytest.mark.skip
    def test_dragdrop(self):
        self.driver.get('http://sahitest.com/demo/dragDropMooTools.htm')
        drag_ele = self.driver.find_element_by_id('dragger')
        drop1_ele = self.driver.find_element_by_xpath(
            '//*[@class="item"][1]')  # 第一个放置框
        drop2_ele = self.driver.find_element_by_xpath(
            '//*[@class="item"][2]')  # 第二个放置框
        drop3_ele = self.driver.find_element_by_xpath(
            '//*[@class="item"][3]')  # 第三个放置框
        drop4_ele = self.driver.find_element_by_xpath(
            '//*[@class="item"][4]')  # 第四个放置框

        # 方法一
        self.action.drag_and_drop(drag_ele,
                                  drop1_ele).perform()  # 将第一个元素拖拽到第二个元素
        # 方法二
        self.action.click_and_hold(drag_ele).release(
            drop2_ele).perform()  # 先按住,再释放
        # 方法三
        self.action.click_and_hold(drag_ele).move_to_element(
            drop3_ele).release().perform()
        sleep(3)

    def test_keys(self):
        self.driver.get('http://sahitest.com/demo/label.htm')
        ele = self.driver.find_element_by_xpath('//input[@type="textbox"][1]')
        ele.click()
        self.action.send_keys('username').pause(1)  # 输入username并暂停一秒
        self.action.send_keys(Keys.SPACE).pause(1)  # 输入空格并暂停一秒
        self.action.send_keys('tom').pause(1)
        self.action.send_keys(Keys.BACK_SPACE).perform()  # 删除输入的内容
        sleep(3)
Exemple #48
0
def getCommentFrom(driver, url):
    'yield 依次返回一个作品中的所有评论'
    driver.get(url)

    products = driver.find_elements_by_xpath('//div[@class="work-card"]')

    for each in products:
        try:
            each.click()
            print(each.text)
        except Exception as e:
            print('open product error,', e)

        try:
            # 两次点击使视频暂停, 有些作品不是视频,不需要停止
            driver.find_element_by_xpath('//span[@class="play-icon"]').click()
            driver.find_element_by_xpath('//span[@class="play-icon"]').click()
        except Exception as e:
            print(e, 'no play icon')
        # 运行逻辑, 每步骤间应该加入try防止异常
        # 鼠标滚到最底下
        # 打开所有的子评论
        # 开始抓取

        commentList = driver.find_element_by_xpath('//div[@class="comment"]')

        # 滚到最底下
        count = 0
        try:
            action = ActionChains(driver)
            prev_last_comment = ''
            curr_last_comment = driver.find_elements_by_xpath(
                '//div[@class="comment-item-body"]')[-1]
            error_time = 0  # 防止网络卡导致元素未加载
            while (prev_last_comment != curr_last_comment):
                prev_last_comment = curr_last_comment
                action.drag_and_drop(commentList, prev_last_comment)
                action.perform()
                time.sleep(0.5)  # 等待元素加载
                curr_last_comment = driver.find_elements_by_xpath(
                    '//div[@class="comment-item-body"]')[-1]
                count += 1
                print(count)
        except Exception as e:
            print("rolling error", e)

        print('totally run', count)
        print('pull over')

        # 打开所有子评论, ???需要打开窗口,否则会失灵, 鼠标会被占用
        try:
            expands = driver.find_elements_by_xpath(
                '//div[@class="more-sub-expand"]')
            expands_count = len(expands)
            for each in expands:
                each.click()
                time.sleep(0.1)
        except Exception as e:
            print('open sub comment error', e)

        # 读取所有加载出来的评论
        try:
            comments = driver.find_elements_by_xpath(
                '//div[@class="comment-item-body"]')
            subComments = driver.find_elements_by_xpath(
                '//div[@class="comment-sub-item"]')
        except Exception as e:
            print('read comment error', e)
        print('now have', len(comments))
        print('expand count', expands_count)
        print('now have', len(subComments))

        # 关闭当前作品
        time.sleep(2)  # 暂停
        try:
            close_icon = driver.find_element_by_xpath('//div[@class="close"]')
            if type(close_icon) is list:
                close_icon[0].click()
            else:
                close_icon.click()
        except Exception as e:
            print('close product error', e)
        yield comments + subComments
Exemple #49
0
input.send_keys('iPad')
button = browser.find_element_by_class_name('btn-search')
button.click()

# 5 动作链
from selenium import webdriver
from selenium.webdriver import ActionChains

browser = webdriver.Chrome()
url = 'http://www.runoob.com/try/try.php?filename=jqueryui-api-droppable'
browser.get(url)
browser.switch_to.frame('iframeResult')
source = browser.find_element_by_css_selector('#draggable')
target = browser.find_element_by_css_selector('#droppable')
actions = ActionChains(browser)
actions.drag_and_drop(source, target)  #拖拽操作
actions.perform()

# 6 执行js
browser = webdriver.Chrome()
browser.get('https://www.zhihu.com/explore')
browser.execute_script('window.scrollTo(0, document.body.scrollHeight)')
browser.execute_script('alert("To Bottom")')

# 7 获取节点信息
from selenium import webdriver
from selenium.webdriver import ActionChains

browser = webdriver.Chrome()
url = 'https://www.zhihu.com/explore'
browser.get(url)
 def drag_item_to_zone(self, item_value, zone_id):
     element = self._get_unplaced_item_by_value(item_value)
     target = self._get_zone_by_id(zone_id)
     action_chains = ActionChains(self.browser)
     action_chains.drag_and_drop(element, target).perform()
Exemple #51
0
 def drag_and_drop_element_to_element(self, element, element_final):
     action = ActionChains(self.driver)
     action.drag_and_drop(element, element_final).release().perform()
Exemple #52
0
    def test_storymap(self):
        factories.UserFactory.create(
            email="*****@*****.**",
            password="******",
            is_staff=True,
        )
        self._login("*****@*****.**", "123")
        time.sleep(0.2)
        storymap = factories.StoryMapFactory.create()
        self.browser.get(
            self.live_reverse("storymap_detail", args=(storymap.pk, )))
        time.sleep(0.2)
        # Create 2 themes
        for seq in range(2):
            self.sel_query("a.create_theme").click()
            time.sleep(0.2)
            theme_input = self.sel_query("#theme-create-panel textarea")
            theme_input.send_keys("Theme {0}".format(seq))
            self.sel_query("#create-theme-btn").click()
            time.sleep(0.5)
        # Create 2 phase
        for seq in range(2):
            self.sel_query("a.create_phase").click()
            time.sleep(0.2)
            theme_input = self.sel_query("#phase-create-panel textarea")
            theme_input.send_keys("Phase {0}".format(seq))
            self.sel_query("#create-phase-btn").click()
            time.sleep(0.5)
        # let's move to the theme and phase to display the "new story" button
        actionChains = ActionChains(self.browser)
        actionChains.move_to_element(self.sel_query(".stories-zone"))
        actionChains.perform()
        time.sleep(0.2)
        self.sel_query(".create_story").click()
        time.sleep(0.2)
        actionChains = ActionChains(self.browser)
        actionChains.send_keys("My first story\n")
        actionChains.perform()
        time.sleep(0.2)

        actionChains = ActionChains(self.browser)
        actionChains.move_to_element(self.sel_query(".stories-zone"))
        actionChains.perform()
        time.sleep(0.2)
        self.sel_query(".create_story").click()
        actionChains = ActionChains(self.browser)
        actionChains.send_keys("My second story\n")
        actionChains.perform()
        time.sleep(0.2)

        story = Story.objects.get(title="My first story")
        phase_1 = Phase.objects.get(name="Phase 1")
        theme_0 = Theme.objects.get(name="Theme 0")

        # move story to another phase
        actionChains = ActionChains(self.browser)
        actionChains.drag_and_drop(
            self.sel_query('.story-cell[story-id="{0}"]'.format(story.pk)),
            self.sel_query('.stories-zone[phase-id="{0}"]'.format(phase_1.pk)),
        )
        actionChains.perform()
        time.sleep(0.2)

        storymap = StoryMap.objects.get(pk=storymap.pk)
        self.assertEqual(storymap.themes.all()[0].name, "Theme 0")
        self.assertEqual(storymap.themes.all()[1].name, "Theme 1")
        self.assertEqual(storymap.phases.all()[0].name, "Phase 0")
        self.assertEqual(storymap.phases.all()[1].name, "Phase 1")
        story = Story.objects.get(title="My first story")
        self.assertEqual(story.phase_id, phase_1.pk)
        self.assertEqual(story.theme_id, theme_0.pk)

        # Edit story
        actionChains = ActionChains(self.browser)
        actionChains.click(
            self.sel_query('.story-cell[story-id="{0}"] .story'.format(
                story.pk)))
        actionChains.perform()
        actionChains = ActionChains(self.browser)
        actionChains.send_keys(" Edited\n")
        actionChains.perform()
        time.sleep(1)

        self.assertTrue(Story.objects.get(title="My first story Edited"))

        # delete theme 1
        theme = Theme.objects.get(name="Theme 1")
        actionChains = ActionChains(self.browser)
        actionChains.move_to_element(
            self.sel_query('.theme-cell[theme-id="{0}"]'.format(theme.pk)))
        actionChains.click(
            self.sel_query('.theme-cell[theme-id="{0}"] .delete_theme'.format(
                theme.pk)))
        actionChains.perform()
        time.sleep(0.2)
        self.sel_query("#confirm-delete-btn").click()
        time.sleep(0.5)

        # delete phase 0
        phase = Phase.objects.get(name="Phase 0")
        actionChains = ActionChains(self.browser)
        actionChains.move_to_element(
            self.sel_query('.phase-cell[phase-id="{0}"]'.format(phase.pk)))
        actionChains.click(
            self.sel_query('.phase-cell[phase-id="{0}"] .delete_phase'.format(
                phase.pk)))
        actionChains.perform()
        time.sleep(0.2)
        self.sel_query("#confirm-delete-btn").click()
        time.sleep(0.5)

        # delete last story
        actionChains = ActionChains(self.browser)
        actionChains.move_to_element(
            self.sel_query('.story-cell[story-id="{0}"]'.format(story.pk)))
        actionChains.click(
            self.sel_query('.story-cell[story-id="{0}"] .delete_story'.format(
                story.pk)))
        actionChains.perform()
        time.sleep(0.2)
        self.sel_query("#confirm-delete-btn").click()
        time.sleep(0.5)

        # Only one story theme and phase should exists
        self.assertFalse(Story.objects.exists())
        self.assertTrue(Theme.objects.get())
        self.assertTrue(Theme.objects.get())
Exemple #53
0
from selenium import webdriver
from selenium.webdriver import ActionChains

driver = webdriver.Chrome(
    executable_path="C:\Python27\Scripts\chromedriver.exe")
driver.get("https://opensource-demo.orangehrmlive.com/")
driver.find_element_by_id("txtUsername").send_keys("Admin")
driver.find_element_by_id("txtPassword").send_keys("admin123")
driver.find_element_by_id("btnLogin").click()

source_element = driver.find_element_by_id("menu_admin_viewAdminModule")
target_element = driver.find_element_by_id("menu_admin_UserManagement")

actions = ActionChains(driver)
actions.drag_and_drop(source_element, target_element).perform()
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver import ActionChains
import time

options = Options()
options.binary_location = 'C:/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe'
driver_path = 'D:/certificates/Selenium/Drivers/chromedriver.exe'
driver = webdriver.Chrome(options = options, executable_path = driver_path)

driver.get("http://dhtmlgoodies.com/scripts/drag-drop-custom/demo-drag-drop-3.html")
driver.maximize_window()

sourceElement = driver.find_element_by_xpath("//*[@id='box6']")
destElement = driver.find_element_by_xpath("//*[@id='box106']")

actions = ActionChains(driver)

actions.drag_and_drop(sourceElement, destElement).perform()



time.sleep(5)
driver.quit()
Exemple #55
0
 def drag_and_drop(self, src, dest):
     action = ActionChains(self.driver)
     action.drag_and_drop(src, dest).perform()
from selenium import webdriver
from selenium.webdriver import ActionChains
import time

driver = webdriver.Chrome()
driver.get("https://the-internet.herokuapp.com/drag_and_drop")
driver.maximize_window()
time.sleep(3)

element_a = driver.find_element_by_id("column-a")
element_b = driver.find_element_by_id("column-b")

action_chains = ActionChains(driver)
action_chains.drag_and_drop(element_a, element_b).perform()
time.sleep(1)
action_chains.drag_and_drop(element_b, element_a).perform()

driver.get("https://www.testandquiz.com/selenium/testing.html")
time.sleep(3)

sourceImage = driver.find_element_by_id("sourceImage")
targetDiv = driver.find_element_by_id("targetDiv")

action_chains = ActionChains(driver)
action_chains.drag_and_drop(sourceImage, targetDiv).perform()

driver.close()
    def test_filediffreviewer_buttons(self):
        """Clicking on the review status should change its text and class"""

        self.reviewboard_login('*****@*****.**', 'password3')
        self.load_rburl('r/1/diff/1/')

        self.assertTrue(
            self._element_is_present((By.CLASS_NAME, 'diff-file-btn'))
        )

        review_button = self.browser.find_element_by_class_name(
            'diff-file-btn')
        self.assertEqual(review_button.text, 'not reviewed')
        self.assertEqual(review_button.get_attribute('class'),
                         'diff-file-btn')

        # clicking on the button should switch to `reviewed`
        review_button.click()
        WebDriverWait(self.browser, 10).until(
            EC.element_to_be_clickable(
                (By.CLASS_NAME, 'diff-file-btn')))

        self.assertEqual(review_button.text, 'reviewed')
        self.assertEqual(review_button.get_attribute('class'),
                         'diff-file-btn reviewed')

        # another click should switch it back to `not reviewed`
        review_button.click()
        WebDriverWait(self.browser, 10).until(
            EC.element_to_be_clickable(
                (By.CLASS_NAME, 'diff-file-btn')))

        self.assertEqual(review_button.text, 'not reviewed')
        self.assertEqual(review_button.get_attribute('class'),
                         'diff-file-btn')

        left_revision_selector = self.browser.find_elements_by_class_name(
            'revision-selector-handle')[0]
        right_revision_selector = self.browser.find_elements_by_class_name(
            'revision-selector-handle')[1]

        first_revision = self.browser.find_elements_by_class_name(
            'revision-selector-tick')[1]
        last_revision = self.browser.find_elements_by_class_name(
            'revision-selector-tick')[2]

        action_chains = ActionChains(self.browser)
        action_chains.drag_and_drop(right_revision_selector,
                                    first_revision).perform()

        WebDriverWait(self.browser, 10).until(
            EC.text_to_be_present_in_element(
                (By.CSS_SELECTOR, '#diff_revision_label h1'),
                'Diff Revision 1'
            )
        )

        self.assertTrue(
            self._element_is_present((By.CLASS_NAME, 'diff-file-btn'))
        )

        action_chains.drag_and_drop(right_revision_selector,
                                    last_revision).perform()

        action_chains.drag_and_drop(left_revision_selector,
                                    first_revision).perform()

        WebDriverWait(self.browser, 10).until(
            EC.text_to_be_present_in_element(
                (By.CSS_SELECTOR, '#diff_revision_label h1'),
                'Changes between revision 1 and 2'
            )
        )

        self.assertFalse(
            self._element_is_present((By.CLASS_NAME, 'diff-file-btn'))
        )
def drag_and_drop_elements(browser, src_element, target_element):
    act = ActionChains(browser)
    act.drag_and_drop(src_element, target_element).perform()
Exemple #59
0
from selenium import webdriver as wd
from selenium.webdriver import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time

driver = wd.Chrome(r"<path>/chromedriver.exe")
driver.get('https://www.globalsqa.com/demo-site/draganddrop/')
driver.maximize_window()
driver.implicitly_wait(10)
ac = ActionChains(driver)
ele10 = driver.find_element_by_xpath(
    "//iframe[@class='demo-frame lazyloaded']")
driver.switch_to.frame(ele10)
ele1 = driver.find_element_by_xpath(
    '//li[contains(@class, "ui-widget-content ui-corner-tr ui-draggable ui-draggable-handle")]//img[@src="images/high_tatras_min.jpg"]'
)
ele2 = driver.find_element_by_xpath('//div[@id="trash"]')
ac.drag_and_drop(ele1, ele2).perform()

#finally done
Exemple #60
0
from selenium import webdriver
from selenium.webdriver import ActionChains
import time

driver = webdriver.Chrome('chromedriver.exe')
driver.maximize_window()

driver.get('https://www.seleniumeasy.com/test/drag-and-drop-demo.html')

drag = driver.find_element_by_xpath('//*[@id="todrag"]/span[2]')
drop1 = driver.find_element_by_xpath('//*[@id="mydropzone"]')
#time.sleep(1)
action = ActionChains(driver)
action.drag_and_drop(drag, drop1).perform()