from selenium_lab import *
@case('selenium-mouse-and-keyboard-operation')
def actions(l,d,b,s):
ActionChains(d).click(d.find_element(By.ID,'button')).perform();l.eq('pointer-click-count',d.find_element(By.ID,'clicked').text,'1');ActionChains(d).double_click(d.find_element(By.ID,'double')).perform();l.eq('double-event',d.find_element(By.ID,'doubled').text,'1');ActionChains(d).context_click(d.find_element(By.ID,'context')).perform();l.eq('right-event',d.find_element(By.ID,'context-count').text,'1');ActionChains(d).move_to_element(d.find_element(By.ID,'hoverbox')).perform();l.check('hover-tip-visible',d.find_element(By.ID,'hover-tip').is_displayed());source=d.find_element(By.ID,'dragger');target=d.find_element(By.ID,'dropzone');ActionChains(d).drag_and_drop(source,target).perform();l.eq('actual-pointer-drop',d.find_element(By.ID,'drag-result').text,'已移到目标区域');l.eq('down-up-events',d.find_element(By.ID,'drag-events').text,'down up');box=d.find_element(By.ID,'keyboard');box.send_keys('old text');ActionChains(d).click(box).key_down(Keys.CONTROL).send_keys('a').key_up(Keys.CONTROL).send_keys('mbsky.com').perform();l.eq('select-and-replace',box.get_property('value'),'mbsky.com');box.clear();ActionChains(d).click(box).key_down(Keys.SHIFT).send_keys('a').key_up(Keys.SHIFT).perform();l.eq('shift-upper',box.get_property('value'),'A');box.send_keys(Keys.TAB);l.eq('tab-focus',d.switch_to.active_element.get_attribute('id'),'next-focus');ActionChains(d).reset_actions();l.pending_case('native-clipboard-and-HTML5-DataTransfer','No user clipboard access; actual pointer drag fixture tested, arbitrary native/HTML5DataTransfer widgets not accepted')
if __name__ == "__main__":
run('selenium-mouse-and-keyboard-operation')
本例需在 Windows/Python3.12/Selenium4.52.0/Edge及驱动156.0.4314.58;GridServer4.52/Temurin21.0.13;独立无头会话 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Windows/Python3.12/Selenium4.52.0/Edge及驱动156.0.4314.58;GridServer4.52/Temurin21.0.13;独立无头会话
入口文件:projects/selenium-lab/selenium-mouse-and-keyboard-operation.py
预期结果与验证条件观察提示
- 本章固定输入断言通过,错误/等待/业务结果和退出分别验证
- 截图对应本站当前测试页;未执行平台或能力不因本轮通过自动升级
请结合实际环境逐项观察。
附件与关联工程包下载
课程关联工程包(登记关联15章) · 含当前章节或实例 · mbskycom202611a531.zip