Command Execute Script
Script starting with "mobile:" prefix supports following commands:
-
start
- simulate pressing Start/Windows hardware button -
search
- simulate pressing Search hardware button -
OnScreenKeyboard.Enable
- show on-screen keyboard -
OnScreenKeyboard.Disable
- hide on-screen keyboard
OnScreenKeyboard.Enable
andOnScreenKeyboard.Disable
introduced in v1.1.1.
Examples
self.driver.execute_script("mobile: start")
self.driver.execute_script("mobile: search")
self.driver.execute_script("mobile: OnScreenKeyboard.Disable")
self.driver.execute_script("mobile: OnScreenKeyboard.Enable")
Script starting with "automation:" prefix supports following commands:
-
InvokePattern.Invoke
- send a request to activate a control and initiate invoke action. Script argument: -
element
- WebElement on wich attribute will be set -
TogglePattern.Toggle
- cycle through the toggle states (in this order: On, Off and, if supported, Indeterminate.) of an element. Script argument: -
element
- WebElement on wich attribute will be set -
TogglePattern.ToggleState
- retrieve the toggle state of an element. Script argument: -
element
- WebElement on wich attribute will be set -
ScrollPattern.Scroll
- send a request to activate a control and initiate scroll action. Script arguments: -
element
- WebElement on wich attribute will be set -
scroll info
- dictionary. Supported keys: 'v' or 'vertical' key for set vertically scroll amount; 'h' or 'horizontal' key for set vertically scroll amount; 'count' key for set number of repeats (default value = 1). Supported value for 'v'/'h' keys: 'largeDecrement' equivalent to PageUp or clicking on a blank part of a scrollbar; 'largeIncrement' - equivalent to a PageDown or clicking on the track of a scrollbar component; 'NoAmount' - specifies that scrolling should not be performed (is default value); 'smallDecrement' - equivalent to pressing an arrow key or clicking the arrow button on a scrollbar; 'smallIncrement' - equivalent to pressing an arrow key or clicking the arrow button on a scrollbar -
GetClickablePoint
- get clickable point. Can be used to bypass bug with incorrect click location when app screen is pulled up due to on-screen keyborad being shown. Script arguments: -
element
- WebElement to get clickable point for
TogglePattern.Toggle
,TogglePattern.ToggleState
introduced in v1.0.1. In v1.0.1invoke
renamed toInvokePattern.Invoke
,scroll
renamed toScrollPattern.Scroll
.
GetClickablePoint
introduced in v1.1.1.
app_bar_button = self.driver.find_element_by_id("GoAppBarButton")
self.driver.execute_script("automation: InvokePattern.Invoke", app_bar_button)
list_box = self.driver.find_element_by_id("ListBox")
scroll_info = {"v": "smallIncrement", "count": 10}
self.driver.execute_script("automation: ScrollPattern.Scroll", list_box, scroll_info)
start_state = self.driver.execute_script("automation: TogglePattern.ToggleState", element)
self.driver.execute_script("automation: TogglePattern.Toggle", element)
end_state = self.driver.execute_script("automation: TogglePattern.ToggleState", element)
# click element using GetClickablePoint and ActionChains
suggest = self.driver.find_element_by_class_name('Windows.UI.Xaml.Controls.TextBlock')
point = self.driver.execute_script('automation: GetClickablePoint', suggest)
x, y = [float(v) for v in point.split(',')]
ActionChains(self.driver).move_by_offset(x, y).click().perform()
Script starting with "attribute:" prefix supports following commands:
-
set
- sets property on elemenet to specified value, script arguments: -
element
- WebElement on wich attribute will be set -
attribute name
- property name to be set, nested property can be set using dot syntax, e.g., for "Background.Opacity" -
value
- value to be set
Examples
text_box = self.driver.find_element_by_id('MyTextBox')
self.driver.execute_script("attribute: set", text_box, 'Width', 10)
self.driver.execute_script("attribute: set", text_box, 'Background.Opacity', 0.3)