Module to find the closest match of a string in a list

exception pywinauto.findbestmatch.MatchError(items=None, tofind='')

A suitable match could not be found

class pywinauto.findbestmatch.UniqueDict

A dictionary subclass that handles making its keys unique

find_best_matches(search_text, clean=False, ignore_case=False)

Return the best matches for search_text in the items

  • search_text the text to look for
  • clean whether to clean non text characters out of the strings
  • ignore_case compare strings case insensitively

Build the disambiguated list of controls

Separated out to a different function so that we can get the control identifiers for printing.

pywinauto.findbestmatch.find_best_control_matches(search_text, controls)

Returns the control that is the the best match to search_text

This is slightly differnt from find_best_match in that it builds up the list of text items to search through using information from each control. So for example for there is an OK, Button then the following are all added to the search list: “OK”, “Button”, “OKButton”

But if there is a ListView (which do not have visible ‘text’) then it will just add “ListView”.

pywinauto.findbestmatch.find_best_match(search_text, item_texts, items, limit_ratio=0.5)

Return the item that best matches the search_text

  • search_text The text to search for
  • item_texts The list of texts to search through
  • items The list of items corresponding (1 to 1) to the list of texts to search through.
  • limit_ratio How well the text has to match the best match. If the best match matches lower then this then it is not considered a match and a MatchError is raised, (default = .5)
pywinauto.findbestmatch.get_control_names(control, allcontrols, textcontrols)

Returns a list of names for this control

pywinauto.findbestmatch.get_non_text_control_name(ctrl, controls, text_ctrls)

return the name for this control by finding the closest text control above and to its left

pywinauto.findbestmatch.is_above_or_to_left(ref_control, other_ctrl)

Return true if the other_ctrl is above or to the left of ref_control