9

How to make Python code in WebDriver to press Command+Shift+H buttons on keyboard (or keys)?

Update:

info: Pushing command to appium work queue: "au.mainApp().getTreeForXML()"
debug: Sending command to instruments: au.mainApp().getTreeForXML()
info: [INSTSERVER] Sending command to instruments: au.mainApp().getTreeForXML()
info: [INSTSERVER] Socket data received (8192 bytes)
info: [INSTSERVER] Socket data received (4494 bytes)
info: [INSTSERVER] Socket data being routed for 'cmd' event
info: [INSTSERVER] Got result from instruments: {"status":0,"value":"{\"UIAApplication\":{\"@\":{\"name\":\"AppName\",\"label\":\"AppName\",\"value\":null,\"dom\":null,\"enabled\":true,\"valid\":true,\"visible\":true,\"hint\":null,\"path\":\"/0\",\"x\":0,\"y\":20,\"width\":320,\"height\":548},\">\":[{\"UIAWindow\":{\"@\":{\"name\":null,\"label\":
Kirill
  • 1,530
  • 5
  • 24
  • 48

1 Answers1

12

Use send_keys():

from selenium.webdriver.common.keys import Keys

element.send_keys(Keys.COMMAND, Keys.SHIFT, 'H')

Also see: The Keys implementation.

powlo
  • 2,538
  • 3
  • 28
  • 38
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • I am trying to press "Home" button in iOS Simulator. It says `wd.send_keys(Keys.COMMAND, Keys.SHIFT, 'H') AttributeError: 'WebDriver' object has no attribute 'send_keys'` – Kirill Apr 21 '14 at 21:37
  • 2
    @KirillZhukov you should first find an element to execute a `send_keys()`. `send_keys()` is a method of a WebDriver element. – alecxe Apr 21 '14 at 21:39
  • 1
    @KirillZhukov `wd` is a `WebDriver` instance, not element. – alecxe Apr 21 '14 at 21:41
  • So, how can I get the first element, aka main window? – Kirill Apr 21 '14 at 21:53
  • @KirillZhukov could you give me the url so I can test? – alecxe Apr 21 '14 at 21:56