robocorp / rpaframework

Collection of open-source libraries and tools for Robotic Process Automation (RPA), designed to be used with both Robot Framework and Python
https://www.rpaframework.org/
Apache License 2.0
1.17k stars 225 forks source link

Windows locators: unable to search element with trailing space in class name #1151

Open ynerant opened 9 months ago

ynerant commented 9 months ago

Hi,

I am automating tests for an evil application that have class names that ends with a trailing whitespace.

Unfortunately, it seems impossible for now to match some such elements, since the locator query is trimmed. I found some hack using subname or regex, but that only works for names and not for classes.

Do you know any hack that let find search my element by class name (for now I am doing differently), or is there any solution to fix that issue?

By the way, is it possible to locate only one class among multiple ones?

kkotenko commented 9 months ago

Hi @ynerant, an approach I have used for similar problems in the past would be to:

1) Get the parent element of the element you actually want 2) Get a list of the children (I have found that Get elements regex:.* root_element=<parent> works best - in fact, it is about 30% faster than Print Tree with depth 1 for this) 3) Iterate over the list 4) Check the class of every element using Get Attribute. If it matches your search string, return.

If you wanted to check other properties of ${element} than those exposed by WindowsElement, you would have to do Evaluate $element.item.<propertyname>.

ynerant commented 8 months ago

Humm yes, that works for my usage, but I think that it stays a bug of RPA Framework, so I think that I'll leave the issue open.

It would be nice if we can match a "subclass", either a substring of the class field, or if a windows element contains multiple classes separated by spaces, match on one of these classes.