Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Find All Elements" issue with backslashes in Name or AutomationId #214

Open
tpfahler opened this issue Oct 20, 2024 · 0 comments
Open

"Find All Elements" issue with backslashes in Name or AutomationId #214

tpfahler opened this issue Oct 20, 2024 · 0 comments

Comments

@tpfahler
Copy link

tpfahler commented Oct 20, 2024

Example:
The address bar in a simple "open file" dialogue on a Windows 11 system has AutomationId 1001:
image
However if the selected directory is C:\Windows, the element Name is "Addresse: C:\Windows" and
FlaUILibrary.Find All Elements //*[@AutomationId="1001"]
will fail with
[ FAIL ] error: bad escape \W at position 19
because of the "\W" part in the Name property.
We had similar issues with AutomationIds which contain backslashes, e.g. "Table\1;1".

I think the root cause is in robotframework-flaui/src/.../util/automationelement.py, in the method _get_argument_in_xpath:
The implementation uses regex to build the xpath string properties for AutomationId, Name and ClassName, but the substitution is very likely to fail if the replacement value contains a backslash. The python doc states: "if it is a string, any backslash escapes in it are processed."
When we feed the name "Addresse: C:\Windows" to the python code,
re.sub(r"\[\d+]", "[@Name=\"Adresse: C:\\Windows\"]", "Foo[1]")
will throw exactly the same error message as the FlaUILibrary keyword in the example above.

I suggest the following fix, inspired by the comment at the end of the section in the python doc:

Replace line 34 in automationelement.py
xpaths[-1] = re.sub(r"\[\d+]", argument, xpaths[-1])
with
xpaths[-1] = re.sub(r"\[\d+]", argument.replace('\\',r'\\'), xpaths[-1])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant