1"use strict";(self.webpackChunkplaywright_dev=self.webpackChunkplaywright_dev||[]).push([["1830"],{44156(e,s,n){n.r(s),n.d(s,{metadata:()=>r,default:()=>h,frontMatter:()=>c,contentTitle:()=>o,toc:()=>t,assets:()=>l});var r=JSON.parse('{"id":"commands/keyboard-mouse","title":"Keyboard & Mouse","description":"Keyboard","source":"@site/agent-cli/commands/keyboard-mouse.mdx","sourceDirName":"commands","slug":"/commands/keyboard-mouse","permalink":"/agent-cli/commands/keyboard-mouse","draft":false,"unlisted":false,"tags":[],"version":"current","frontMatter":{"title":"Keyboard & Mouse"},"sidebar":"agentCli","previous":{"title":"Interaction","permalink":"/agent-cli/commands/interaction"},"next":{"title":"Tabs","permalink":"/agent-cli/commands/tabs"}}'),i=n(74848),d=n(28453);let c={title:"Keyboard & Mouse"},o="Keyboard & Mouse",l={},t=[{value:"Keyboard",id:"keyboard",level:2},{value:"Common keys",id:"common-keys",level:3},{value:"Key combinations",id:"key-combinations",level:3},{value:"Keyboard navigation",id:"keyboard-navigation",level:3},{value:"Mouse",id:"mouse",level:2},{value:"When to use mouse commands",id:"when-to-use-mouse-commands",level:3}];function a(e){let s={a:"a",code:"code",h1:"h1",h2:"h2",h3:"h3",header:"header",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",...(0,d.R)(),...e.components};return(0,i.jsxs)(i.Fragment,{children:[(0,i.jsx)(s.header,{children:(0,i.jsx)(s.h1,{id:"keyboard--mouse",children:"Keyboard & Mouse"})}),"\n",(0,i.jsx)(s.h2,{id:"keyboard",children:"Keyboard"}),"\n",(0,i.jsxs)(s.table,{children:[(0,i.jsx)(s.thead,{children:(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.th,{children:"Command"}),(0,i.jsx)(s.th,{children:"Description"})]})}),(0,i.jsxs)(s.tbody,{children:[(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"press <key>"})}),(0,i.jsxs)(s.td,{children:["Press a key (e.g., ",(0,i.jsx)(s.code,{children:"Enter"}),", ",(0,i.jsx)(s.code,{children:"ArrowLeft"}),", ",(0,i.jsx)(s.code,{children:"a"}),")"]})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"keydown <key>"})}),(0,i.jsx)(s.td,{children:"Press key down"})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"keyup <key>"})}),(0,i.jsx)(s.td,{children:"Release key"})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"type <text>"})}),(0,i.jsx)(s.td,{children:"Type text key by key into the focused element"})]})]})]}),"\n",(0,i.jsx)(s.h3,{id:"common-keys",children:"Common keys"}),"\n",(0,i.jsxs)(s.p,{children:[(0,i.jsx)(s.code,{children:"Enter"}),", ",(0,i.jsx)(s.code,{children:"Tab"}),", ",(0,i.jsx)(s.code,{children:"Escape"}),", ",(0,i.jsx)(s.code,{children:"Backspace"}),", ",(0,i.jsx)(s.code,{children:"Delete"}),", ",(0,i.jsx)(s.code,{children:"Space"}),",\n",(0,i.jsx)(s.code,{children:"ArrowUp"}),", ",(0,i.jsx)(s.code,{children:"ArrowDown"}),", ",(0,i.jsx)(s.code,{children:"ArrowLeft"}),", ",(0,i.jsx)(s.code,{children:"ArrowRight"}),",\n",(0,i.jsx)(s.code,{children:"Home"}),", ",(0,i.jsx)(s.code,{children:"End"}),", ",(0,i.jsx)(s.code,{children:"PageUp"}),", ",(0,i.jsx)(s.code,{children:"PageDown"})]}),"\n",(0,i.jsx)(s.h3,{id:"key-combinations",children:"Key combinations"}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-bash",children:"playwright-cli press Control+a # select all\nplaywright-cli press Control+c # copy\nplaywright-cli press Control+v # paste\nplaywright-cli press Shift+Tab # focus previous\nplaywright-cli press Alt+Enter # alt+enter\n"})}),"\n",(0,i.jsxs)(s.p,{children:[(0,i.jsx)(s.code,{children:"keydown"})," / ",(0,i.jsx)(s.code,{children:"keyup"})," hold a modifier across several commands, which ",(0,i.jsx)(s.code,{children:"press"})," cannot do:"]}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-bash",children:"playwright-cli keydown Shift\nplaywright-cli click e5\nplaywright-cli click e9 # extends the selection\nplaywright-cli keyup Shift\n"})}),"\n",(0,i.jsxs)(s.p,{children:["To hold modifiers for a single click, ",(0,i.jsx)(s.code,{children:"click --modifiers"})," is simpler \u2014 see\n",(0,i.jsx)(s.a,{href:"/agent-cli/commands/interaction",children:"Interaction"}),"."]}),"\n",(0,i.jsx)(s.h3,{id:"keyboard-navigation",children:"Keyboard navigation"}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-bash",children:"playwright-cli press Tab # next field\nplaywright-cli press Tab # next field\nplaywright-cli press ArrowDown # navigate dropdown\nplaywright-cli press ArrowDown\nplaywright-cli press Enter # select option\n"})}),"\n",(0,i.jsx)(s.h2,{id:"mouse",children:"Mouse"}),"\n",(0,i.jsxs)(s.table,{children:[(0,i.jsx)(s.thead,{children:(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.th,{children:"Command"}),(0,i.jsx)(s.th,{children:"Description"})]})}),(0,i.jsxs)(s.tbody,{children:[(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"mousemove <x> <y>"})}),(0,i.jsx)(s.td,{children:"Move mouse to coordinates"})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"mousedown [button]"})}),(0,i.jsx)(s.td,{children:"Press mouse button (left, right, middle)"})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"mouseup [button]"})}),(0,i.jsx)(s.td,{children:"Release mouse button"})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:(0,i.jsx)(s.code,{children:"mousewheel <dx> <dy>"})}),(0,i.jsx)(s.td,{children:"Scroll (dx=horizontal, dy=vertical)"})]})]})]}),"\n",(0,i.jsxs)(s.p,{children:["Coordinates are viewport-relative
1CSS pixels. ",(0,i.jsx)(s.code,{children:"snapshot --boxes"})," reports each element's box in the\nsame coordinate space, which beats reading positions off a screenshot."]}),"\n",(0,i.jsx)(s.pre,{children:(0,i.jsx)(s.code,{className:"language-bash",children:"# Click at coordinates\nplaywright-cli mousemove 100 200\nplaywright-cli mousedown\nplaywright-cli mouseup\n\n# Right-click\nplaywright-cli mousemove 300 400\nplaywright-cli mousedown right\nplaywright-cli mouseup right\n\n# Scroll down 500 pixels\nplaywright-cli mousewheel 0 500\n\n# Scroll right 200 pixels\nplaywright-cli mousewheel 200 0\n"})}),"\n",(0,i.jsx)(s.h3,{id:"when-to-use-mouse-commands",children:"When to use mouse commands"}),"\n",(0,i.jsxs)(s.table,{children:[(0,i.jsx)(s.thead,{children:(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.th,{children:"Scenario"}),(0,i.jsx)(s.th,{children:"Recommended approach"})]})}),(0,i.jsxs)(s.tbody,{children:[(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:"Clicking a button, link, or form element"}),(0,i.jsxs)(s.td,{children:[(0,i.jsx)(s.code,{children:"click"}),", ",(0,i.jsx)(s.code,{children:"fill"}),", and other ref-based commands"]})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:"Canvas-based apps (drawing, maps)"}),(0,i.jsx)(s.td,{children:"Mouse commands with coordinates"})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:"Custom UI controls without accessibility"}),(0,i.jsx)(s.td,{children:"Mouse commands with coordinates"})]}),(0,i.jsxs)(s.tr,{children:[(0,i.jsx)(s.td,{children:"Drag interactions on pixel-precise targets"}),(0,i.jsx)(s.td,{children:"Mouse commands with coordinates"})]})]})]}),"\n",(0,i.jsxs)(s.p,{children:["For most web applications, ",(0,i.jsx)(s.strong,{children:"refs from accessibility snapshots are more reliable"})," than coordinates. Use mouse commands only when the accessibility tree doesn't expose the elements you need."]})]})}function h(e={}){let{wrapper:s}={...(0,d.R)(),...e.components};return s?(0,i.jsx)(s,{...e,children:(0,i.jsx)(a,{...e})}):a(e)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.