northwoodspd / uia

A ruby gem for interacting with automation elements in Windows
MIT License
17 stars 4 forks source link

regex in name show error #11

Closed SpreadAutomacao closed 7 years ago

SpreadAutomacao commented 7 years ago

Master, How do I put a regex in the name in code below? Show the erro below:

test = selections.find(name: /Autoriza.*/i).as :selection_item

C:/Ruby23/lib/ruby/gems/2.3.0/gems/uia-0.6/lib/uia/finder.rb:43:in `name_condition': no implicit conversion of Regexp into String (TypeError)

my full code: selections = @window.find(control_type: :list).as :selection puts selections test = selections.find(name: 'Agendamento PET CT').as :selection_item

test = selections.find(name: /Autoriza/).as :selection_item # Autorização

test.select
sleep 0.3
test.send_keys :enter
leviwilson commented 7 years ago

@SpreadAutomacao if you are trying to do that from an already found UIA element, that is not supported. Regexp is only supported from the top-level window location if you were to do a

Uia.find_element title: /Autoriza.*/i)`

The reason is that the top-level locator uses basic things like window titles, etc. that use win32 calls to get the values vs. calling into COM / UIA to get the properties of elements. To do the latter, it would be much more expensive to do that.

Is there not an automation id or something else that could be leveraged (exposed by UI Spy or the like) that you could use instead?

SpreadAutomacao commented 7 years ago

Do Not Has ID :( , Is a legacy application. I also made a loop and compares the name, and I got the handle, but it did not work with a handle.

leviwilson commented 7 years ago

Can you highlight what you have in UI Spy or the like (with the tree view of the parents as well) so I can see the properties it has? I might be able to make a suggestion.

The other thing you could do is locate the element yourself and regexp them by doing:

desired = selections.find_all(pattern: :selection_item)
  .find { |e| e.name =~ /Autoriza.*/i)&.as(:selection_item) or fail 'Could not locate'
SpreadAutomacao commented 7 years ago

Thanks very much!!! :+1:

leviwilson commented 7 years ago

Closing this issue