蓝色天空网 · mbsky.com
鼠标和键盘:动作序列与释放
用事件与页面结果证明交互发生。
固定本地测试页的实际浏览器结果,不是在线Python解释器。下载代码后可在独立环境修改输入并重新运行。
本章Python入口 · 完整实验实现 · 本站测试服务 · 本站页面交互

当前输入实际检查
| 实际检查 | 结果 |
|---|---|
| fixture-initial-no-severe-errors | 通过 |
| pointer-click-count | 通过 |
| double-event | 通过 |
| right-event | 通过 |
| hover-tip-visible | 通过 |
| actual-pointer-drop | 通过 |
| down-up-events | 通过 |
| select-and-replace | 通过 |
| shift-upper | 通过 |
| tab-focus | 通过 |
| screenshot-saved-actual-browser | 通过 |
| PNG-magic-actual-browser | 通过 |
| PNG-extent-actual-browser | 通过 |
| all-created-sessions-quit | 通过 |
本章完整入口
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')