Robotcorder icon indicating copy to clipboard operation
Robotcorder copied to clipboard

Escape multiple spaces in xpath

Open json2d opened this issue 7 years ago • 2 comments

Hey awesome project! It definitely makes doing Robot tests a lot easier :smiley:.

The issue I have is when an xpath happens to contain multiple consecutive spaces, like for example:

    Click Element    //button[@class="btn  btn-default"]

And I get the error: expected 1 argument got 2

For this spaces should be escaped so Robot doesn't parse them as delims:

    Click Element    //button[@class="btn\ \ btn-default"]

I could put together a PR, any tips?

json2d avatar Nov 03 '17 01:11 json2d

You can use s.replace(/ (?= )/g, " \\"), which puts a backslash between consecutive spaces.

But if you're going to call it a sanitization function, it should also handle other special characters, such as $ \ . The regex above also doesn't handle leading or trailing spaces of an argument.

Another possibility is to switch the cell delimiter to |, but that just means something different to escape.

leewz avatar Nov 03 '17 05:11 leewz

@leew that seems to work, we can sanitize the attr values here:

https://github.com/sohwendy/Robotcorder/blob/e3765c586f9a708143fe078264d498a0475ffe5a/src/locator/xpath-locator.js#L38

However, switching the cell delimiter would be a change to robotframework, which may be out of scope here.

json2d avatar Nov 03 '17 15:11 json2d