Difference between 17.3.0 and 15.1.0 in Get Element

Hi,

We have a test that when used with 15.1 version of browser library returns element id when using Get Element keyword

But on 17.3 Get Element keyword is returning xpath.

Is there a possibility to force Get Element to return element id instead of xpath on new version?

br,
Tomasz

Currently there is not a way. Can you explain why you would prefer an element ID, instead of the selector?

Hello,

Thank you for the info.

We are using element id with > button and with xpath this does not work :wink: It’s just the way we have our tests created.

I was disappointed when this changed as well. It actually broke some tests.

I was interacting with 5 widgets that could only be identified by a common tag. After getting a list of these 5 items, I needed to track them uniquely while performing various actions. This worked well when it returned element ID.

After upgrading, it began returning an xpath which included an index to identify them. Depending on the action, sometimes the list may change from 5 to 4. Index made it impossible to ensure the right one got removed from the list. All I would know is the list shrunk.

A bit hard to explain since it is kind of product specific. There could potentially be thousands of widgets in this list so it wasn’t realistic to give them unique tags.

Anyway all that to say I would be interested to know if there is a way to do this as well.

Hi @TomekWro and @asdf

One of the great things about Robot Framework is it’s easy to build keywords

In a situation like this you can create your own keyword that provides the old behaviour to your test case rather then rewriting all your test cases, just change the test case to use your own keyword.

If I understood your issue, something like this will probably do what you need:

*** Settings ***
Library    Browser
Library    Collections

Suite Setup 	Open Browser 	https://robotframework.org/ 	chromium
test Teadown 	Close Browser

*** Test Cases ***
Get Element Id Example
	Go To 	https://www.google.com/
	${myid}= 	Get Element Id 	css=.A8SBwf textarea

Get Elements Ids Example
	Go To 	https://robotframework.org/
	${myids}= 	Get Elements Ids 	css=.pt-3xsmall h2

*** Keywords ***

Get Element Id
	[Documentation] 	Returns the id of the selected element
	[Arguments]		${Selector}
	${element}= 	Get Element		${Selector}
	${id}= 	Get Property 	${element} 	id
	[Return] 	${id}

Get Elements Ids
	[Documentation] 	Returns the id of the selected elements
	[Arguments]		${Selector}
	@{Ids}= 			Create List
	${elements}= 	Get Elements		${Selector}
	FOR 	${element} 	IN 	@{elements}
		${id}= 	Get Property 	${element} 	id
		Append To List 	${Ids} 	${id}
	END

	[Return] 	${Ids}

Hope that helps,

Dave.