[Pywinauto-users] Re: [pywinauto - Open Discussion] Match Problem
Status: Alpha
Brought to you by:
mcmahon_m
From: Mark Mc M. <mar...@gm...> - 2006-02-24 18:14:43
|
(Another answer from the SourceForge forums - This is something that different opinions migh help to resolve - if you have a preference can you respond?) Hi Jeff, It makes sense that it should - but as you found out it doesn't. In the latest release I changed the algorithm to make it more flexible - but also make it a little more strict. I use difflib in the Python Standard library to find those texts that are a close match. And that returns a float between 1 and 0 giving how well 2 bits of text match (what you typed in and what the control text is). If a match is below a certain number it is not counted as a match. and the problem here is that the text of the control is long so CSV only matches 3 characters out of the lot.. ctrl =3D "Comma Separated Values file (CSV, best for portable devices)" attr =3D "CSV" import difflib matcher =3D difflib.SequenceMatcher() matcher.set_seqs(ctrl, attr) matcher.ratio() -> 0.095238095238095233 And I cut off somewhere in the range of .6! The only reason that I would be wary of adding a check for the text being in only one control is that things like If app.Dialog.SomeControl.Exists(): # do something with it is too likely to succeed! Just as I wrote the above what I could do is: - Add a flag to my matching method that says whether to do this 'In' searching if all else fails. - This flag would be set for normal attribute resolution - this flag would be unset for Exists But the only problem then is that Exists, Enabled, etc, will behave differently and it could set up some very hard to find bugs e.g. app.dlg.CSV.Click() while not app.dlg.CSV.IsEnabled(): # wait for the control to become enabled after clicking this would not work :-( I have been thinking at various times that it would be nicer to be able to specify title=3D, title_re =3D etc. maybe something like app.dlg.CSV_IN_.Click() ?? This will definitely need some comments before I go for it. for now you can do what you pointed out or maybe app.dlg.window_(title_re =3D ".*CSV.*").Click() but that isn't much less typing is it :-( Thanks Mark On 2/24/06, SourceForge.net <no...@so...> wrote: > > Read and respond to this message at: > https://sourceforge.net/forum/message.php?msg_id=3D3595801 > By: winkler1 > > Issue with finding match: > I've got a dialog with 4 radio buttons, which have these verbose labels: > - Web Page HTML file (for sharing, and printing) > - Comma Separated Values file (CSV, best for portable devices) > - Rich Text Format file (RTF, best for integration with your documents) > - Web Page HTML file (for sharing, and printing) > > The following failed: > app.CollectionExportWizard.CSV.Click() > app.CollectionExportWizard.CommaSeparatedValuesFile.Click() > > Ultimately, I had to fully spell it out. Given the verbosity of the radio= button, > this was pretty painful :) > > app.CollectionExportWizard.CommaSeparatedValuesFileCSVBestForPortableDev= ices.Cl > ick() > > Here's the thing: since "CSV" appears in the text of only one control, sh= ouldn't > it have matched? Although only a small percentage of the characters matc= h on > my target radio button, it's zero percent on all the others. > -- Jeff > > ------ Full dialog dump: > > > MatchError: Could not find 'CommaSeparatedValuesFile' in '['', u'Web Page= HTML > file (for sharing, and printing)RadioButton', u'Collection Export WizardS= tatic', > u'The collection export wizard will guide you through the process of expo= rting > the collection file to a third-party file format for the convenience of p= rinting > and exchanging with others.UpDown', u'HelpButton', u'&Next >', 'ComboBox'= , u'Rich > Text Format file (RTF, best for integration with your documents)RadioButt= on', > u'Rich Text Format file (RTF, best for integration with your documents)', > u'Collection Export Wizard', 'UpDown', u'The collection export wizard wil= l guide > you through the process of exporting the collection file to a third-party= file > format for the convenience of printing and exchanging with others.', u'Ca= ncelButton', > u'With the following file organization:', u'&Next >Button', u'With the fo= llowing > file organization:ComboBox', u'With the following file organization:Stati= c', > u'#32770', 'Button', 'RadioButton3', u'The collection export wizard will = guide > you through the process of exporting the collection file to a third-party= file > format for the convenience of printing and exchanging with others.Static'= , 'Button3', > u'I want to export my collection to:', u'Web Page HTML file (for sharing,= and > printing)', 'Button0', 'Button1', u'Plain text fileRadioButton', u'Help',= 'Static1', > 'Static0', 'Static3', 'Static2', 'Static5', 'Static4', 'Button2', 'RadioB= utton', > u'I want to export my collection to:Static', u'Comma Separated Values fil= e (CSV, > best for portable devices)RadioButton', u'Plain text file', 'RadioButton4= ', > 'Static', 'RadioButton2', 'RadioButton1', 'RadioButton0', u'Cancel', u'Co= llection > Export Wizard#32770', u'Comma Separated Values file (CSV, best for portab= le > devices)']' > > ______________________________________________________________________ > You are receiving this email because you elected to monitor this forum. > To stop monitoring this forum, login to SourceForge.net and visit: > https://sourceforge.net/forum/unmonitor.php?forum_id=3D529286 > |