Skip to content
Nick Abalov edited this page Oct 8, 2016 · 2 revisions

Strategies

v 0.1.5414.25590 or higher

id

Use this when you know AutomationProperties.AutomationId attribute of an element.

driver.find_element_by_id('SearchBar')

name

Use this when you know AutomationProperties.Name attribute of an element.

driver.find_element_by_name('AddressLabel')

⚠️ Note that AutomationProperties.Name is used for accessibility. If you want to set name for automation purpose only and this name will decrease accessibility of your app, consider using AutomationProperties.AutomationId instead.

Before 0.1.5414.25590 name strategy used Name property, not AutomationProperties.Name


tag name

class name

Use this when you want to locate an element by its class name (complete with namespace).

driver.find_element_by_tag_name('System.Windows.Controls.TextBlock')

xname

Transitional. To be depricated. Use this when you want to locate an element by its Name property (NOT AutomationProperties.Name). Not recomended. Add AutomationProperties.Name to the element you are planning to use in test and use name strategy instead.

from selenium.webdriver.common.by import By

By.XNAME = 'xname'  # enable xname as valid By strategy
...

driver.find_elements('xname', 'Title')