selenium-- drag and drop page elements

from selenium import webdriver
import unittest
from selenium.webdriver import ActionChains
import time


class Test_dragpage(unittest.TestCase):
    def test_dragpageElement(self):
        url = 'http://jqueryui.com/resources/demos/draggable/scroll.html'
        self.driver = webdriver.Chrome()
        self.driver.get(url)
        # 获取第一,二,三能拖拽的元素
        drag1 = self.driver.find_element_by_id('draggable')
        drag2 Self.driver.find_element_by_id = ( ' draggable2 ' ) 
        drag3 = self.driver.find_element_by_id ( ' draggable3 ' ) 

        # Create a new ActionChains, the instance of the driver webdriver passed as a parameter value, then performs user operation through WenDriver example 

        action_chains = ActionChains (self.driver)
         # the first page can be a drag on the drag element to the second element position 
        action_chains.drag_and_drop (Drag1, drag2) .perform () 

        # the third page can drag on pull element, 10 pixels to the right dragging, dragging a total five times 
        for I in Range (5 ): 
            action_chains.drag_and_drop_by_offset (drag3, 10, 10  ) .perform ()
            the time.sleep ( 2)


test1 = Test_dragpage()
test1.test_dragpageElement()

 

Guess you like

Origin www.cnblogs.com/zouzou-busy/p/11219884.html