将a拖到b上,有三种方法:
- action.drag_and_drop(a,b).perform()
- action.click_and_hold(a).release(b).perform()
- action.click_and_hold(a).move_to_element(b).release().perform()
实现方式如下:
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
class TestActionChains():
def setup(self):
self.driver = webdriver.Chrome()
# 隐式等待
self.driver.implicitly_wait(5)
self.driver.get('https://sahitest.com/demo/dragDropMooTools.htm')
def teardown(self):
self.driver.quit()
def test_drag(self):
element_drag = self.driver.find_element(By.XPATH, '//*[@id="dragger"]')
element_drog = self.driver.find_element(By.XPATH, '/html/body/div[2]')
action = ActionChains(self.driver)
# 方法一
# action.drag_and_drop(element_drag, element_drog).perform()
# 方法二
action.click_and_hold(element_drag).release(element_drog).perform()
# 方法三
action.click_and_hold(element_drag).move_to_element(element_drog).release().perform()
网友评论