SeleniumLibrary icon indicating copy to clipboard operation
SeleniumLibrary copied to clipboard

Fix _find_by_data_locator

Open markus-leben opened this issue 1 year ago • 1 comments

Off by one in _find_by_data_locator which causes opaque failure on data values which contain a colon.

Example html: <div data-automation-id="foo:bar">This might be trouble</div>

Example robot: Scroll Element Into View data:automation-id:foo:bar

Error message: Provided selector (automation-id:foo:bar) is malformed. Correct format: name:value.

I don't love the person putting colons in their automation ID, but we don't always get to choose the html we're testing.

markus-leben avatar Oct 07 '24 19:10 markus-leben

On second thought it might be a good idea to also change the error raised in the try or the message given in the except. The error that gets caught by that catch is a ValueError about unpacking with string's split() method: ValueError: too many values to unpack (expected 2)

But the error message from the except in _find_by_data_locator catches that ValueError and replaces it with something that's in this case more vague, and implies that the reason the ValueError is raised is because of the condition in the try, rather than an unrelated ValueError.

I'm not sure what the ideal fix here would be though.

markus-leben avatar Oct 08 '24 14:10 markus-leben

I have some unit tests to verify this change which I will submit in another PR.

emanlove avatar Nov 02 '24 20:11 emanlove