You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Example:
The address bar in a simple "open file" dialogue on a Windows 11 system has AutomationId 1001:
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])
The text was updated successfully, but these errors were encountered:
Example:
The address bar in a simple "open file" dialogue on a Windows 11 system has AutomationId 1001:
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])
The text was updated successfully, but these errors were encountered: