-
Notifications
You must be signed in to change notification settings - Fork 11
Getting Started
To get started, follow the instructions to install WinAppDriver and start the server:
NOTE: Windows 10 is not fully supported yet. Please use Windows 7 or 8.x for evaluation.
-
Download the installer (
WinAppDriverInstaller.msi
) from releases page, run it, and follow the installation instructions.For more information about what the installer has done to your compupter, refer to Installation.
-
The installer creates a shortcut named 'WinAppDriver' on the desktop. Use it to launch WinAppDriver server, which listens on port 4444 on all addresses.
To connect to the server, use the remote webdriver of your preferred Selenium language binding. Here we use Python selenium
package (interactive mode):
>>> from selenium.webdriver import Remote
>>> desired_caps = {}
>>> driver = Remote('http://your-winappdriver-server:4444/wd/hub', desired_caps)
In this case, without specifying any desired capabilities, you can interact with UI elements in currently active window (except the lock/login screen).
Take the built-in Calculator (desktop version) as an example. Use Win + R to bring up run dialog box, type calc
and hit Enter:
>>> from selenium.webdriver.common.action_chains import ActionChains
>>> from selenium.webdriver.common.keys import Keys
>>>
>>> ActionChains(driver).key_down(Keys.META).send_keys('r').key_up(Keys.META).perform()
>>>
>>> ActionChains(driver).send_keys('calc' + Keys.ENTER).perform()
TIP: You can specify [[keyboardDelay
|Desired-Capabilities#keyboardDelay]] capability to slow down (or accelerate) typing speed.
Here is the screen recording:
To do a simple calculation, for example 3 x 6 = 18. Although it can be accomplished by using keyboard, we use mouse clicks here for the sake of demonstration.
Before you can interact with a certain UI element, you have to have a reference to the element. Save page source of the currently active window to an external file (/tmp/page.xml
), inspect it, and write relatively reliable locators.
>>> with open('/tmp/page.xml', 'w') as f: f.write(driver.page_source.encode('utf-8'))
Here is a snippet (partially omitted):
<?xml version="1.0" encoding="UTF-8"?>
<WinAppDriver>
<Window id="" framework="Win32" name="Calculator" value="" class="CalcFrame" help="" visible="true" enabled="true" focusable="false" focused="false" selected="false" protected="false" scrollable="false" handle="1442862" x="13" y="173" width="228" height="323" bounds="[13,173][228,323]">
<Pane id="" framework="Win32" name="" value="" class="CalcFrame" help="" visible="true" enabled="true" focusable="false" focused="true" selected="false" protected="false" scrollable="false" handle="1442808" x="21" y="224" width="212" height="264" bounds="[21,224][212,264]">
<!-- omitted -->
<Text id="150" framework="Win32" name="0" value="" class="Static" help="" visible="true" enabled="true" focusable="false" focused="true" selected="false" protected="false" scrollable="false" handle="1639456" x="50" y="249" width="167" height="28" bounds="[50,249][167,28]" />
<!-- omitted -->
<Button id="136" framework="Win32" name="6" value="" class="Button" help="" visible="true" enabled="true" focusable="true" focused="false" selected="false" protected="false" scrollable="false" handle="1573988" x="110" y="385" width="34" height="27" bounds="[110,385][34,27]" />
<Button id="133" framework="Win32" name="3" value="" class="Button" help="" visible="true" enabled="true" focusable="true" focused="false" selected="false" protected="false" scrollable="false" handle="2491210" x="110" y="417" width="34" height="27" bounds="[110,417][34,27]" />
<!-- omitted -->
<Button id="92" framework="Win32" name="Multiply" value="" class="Button" help="" visible="true" enabled="true" focusable="true" focused="false" selected="false" protected="false" scrollable="false" handle="2360410" x="149" y="385" width="34" height="27" bounds="[149,385][34,27]" />
<!-- omitted>
<Button id="121" framework="Win32" name="Equals" value="" class="Button" help="" visible="true" enabled="true" focusable="true" focused="false" selected="false" protected="false" scrollable="false" handle="1901544" x="188" y="417" width="34" height="59" bounds="[188,417][34,59]" />
</Pane>
<!-- omitted -->
</Window>
</WinAppDriver>
TIP: It is recommended to open the XML page source with browsers, especially when the structure is complex. Generally it is not difficult to identify elements you want to interact with directly from page source.
>>> driver.find_element_by_name('3').click()
>>> driver.find_element_by_name('Multiply').click()
>>> driver.find_element_by_name('6').click()
>>> driver.find_element_by_name('Equals').click()
Here is the screen recording: