本文为霍格沃兹测试开发学社学员学习笔记分享
原文链接:https://ceshiren.com/t/topic/27045
使用场景 | 对应事件 |
---|---|
复制粘贴 | 键盘事件 |
拖动元素到某个位置 | 鼠标事件 |
鼠标悬停 | 鼠标事件 |
滚动到某个元素 | 滚动事件 |
使用触控笔点击 | 触控笔事件(了解即可) |
.perform()
代表确定执行。ActionChains(self.driver).操作.perform()
self.driver.find_element(By.XPATH, '//input[@aria-label="搜索"]').send_keys(Keys.ENTER)
self.action.send_keys(Keys.ENTER).perform()
多系统兼容
左箭头:Keys.ARROW_LEFT
按下COMMAND或者CONTROL: key_down(cmd_ctrl)
按下剪切与粘贴按钮: send_keys("xvvvvv")
double_click(元素对象)
: 双击元素 def test_double_click(self):
self.driver.get("https://vip.ceshiren.com/#/ui_study/frame")
ele01 = self.driver.find_element(By.XPATH, '//button[@class="el-button el-button--primary"]')
self.action.double_click(ele01).perform()
time.sleep(3)
drag_and_drop(起始元素对象, 结束元素对象)
: 拖动并放开元素 def test_drag_and_drop(self):
self.driver.get("https://vip.ceshiren.com/#/ui_study/action_chains")
ele01 = self.driver.find_element(By.ID, "item1")
ele02 = self.driver.find_element(By.ID, "item3")
self.action.drag_and_drop(ele01, ele02).perform()
move_to_element(元素对象)
: 移动到某个元素 def test_move_to_element(self):
self.driver.get('https://vip.ceshiren.com/#/ui_study/action_chains2')
ele01 = self.driver.find_element(By.XPATH, '//div [@data-v-3e28c77a and @class="title"]')
self.action.move_to_element(ele01).perform()
self.driver.find_element(By.XPATH, '//*[contains(text(),"管理")]').click()
注意: selenium 版本需要在 4.2 之后才支持滚动操作
def test_scroll_to_element(self):
self.driver.get('https://ceshiren.com/')
ele01 = self.driver.find_element(By.PARTIAL_LINK_TEXT, "jmeter分布式压测创建多节点报错")
self.action.scroll_to_element(ele01).perform()
self.action.scroll_by_amount(0, 100).perform()
ele01.click()
def test_scroll_by_amount(self):
self.driver.get('https://ceshiren.com/')
self.action.scroll_by_amount(0, 1000).perform()