Skip to content

New strategy:value syntax to specify locator strategy in addition to current strategy=value #908

@pekkaklarck

Description

@pekkaklarck

Currently when specifying a non-default locator for an element, the syntax is name=value like in xpath=//h1 or css=h1. This works well otherwise, but the same syntax is also used by Robot Framework's named argument syntax and this can cause confusion.

Using the same syntax also causes actual problems if a keyword would accept **kwargs, because then Robot considers all arguments looking like name=value to match it. There's also a possibility that some time in the future Robot will always do that, regardless on the function signature. Robot allows escaping the problematic = like in name\=value (e.g. css\=h1) but that is a bit ugly if needed often.

My proposal is that in addition to the existing =, we allow using : like name:value (or name: value or even name : value as we allow spaces to used with = too). The reason I propose : is that it's visually quite close to =, it's used by Robot on the command like (e.g. -v name:value), and it's also used by Python in similarly as = in some contexts (e.g.{'name': 'value'} and dict(name=value)). We don't need to deprecate the current syntax at least now, but documentation should be written so that the new syntax is recommended.

This change causes backwards incompatibility problems if someone has used a default locator (e.g. id) which has : in its value like Click Element foo:bar. We don't expect : to be too common in locator values, and there's always a possibility to use id:foo:bar or id=foo:bar to avoid the problem. If there are lot of complaints during the SL 3.0 release candidate phase, we can still consider ways to make the transition smoother.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions